diff options
author | Ben Longbons <b.r.longbons@gmail.com> | 2013-05-25 13:49:50 -0700 |
---|---|---|
committer | Ben Longbons <b.r.longbons@gmail.com> | 2013-05-25 13:49:50 -0700 |
commit | 1d0e18a186f67844ccd873eabb56ebdaa3f47f11 (patch) | |
tree | 94199c6dbcb6b4a86584c303f6e1e72073873f01 /src | |
parent | 87218e07b2bc89593eae1cb4abe859cd1a7eaa0f (diff) | |
download | tmwa-1d0e18a186f67844ccd873eabb56ebdaa3f47f11.tar.gz tmwa-1d0e18a186f67844ccd873eabb56ebdaa3f47f11.tar.bz2 tmwa-1d0e18a186f67844ccd873eabb56ebdaa3f47f11.tar.xz tmwa-1d0e18a186f67844ccd873eabb56ebdaa3f47f11.zip |
Switch block_list and subclasses to dumb_ptr
Now we're well-defined, since we're actually calling ctors and dtors.
Most of this code will not survive long ...
Diffstat (limited to 'src')
41 files changed, 2431 insertions, 2220 deletions
diff --git a/src/common/dumb_ptr.hpp b/src/common/dumb_ptr.hpp index 9321036..1a0b4a1 100644 --- a/src/common/dumb_ptr.hpp +++ b/src/common/dumb_ptr.hpp @@ -28,17 +28,26 @@ template<class T> class dumb_ptr { + template<class U> + friend class dumb_ptr; T *impl; public: explicit dumb_ptr(T *p=nullptr) : impl(p) {} + template<class U> + dumb_ptr(dumb_ptr<U> p) + : impl(p.impl) + {} + dumb_ptr(std::nullptr_t) + : impl(nullptr) + {} void delete_() { delete impl; - forget(); + *this = nullptr; } template<class... A> void new_(A&&... a) @@ -51,9 +60,10 @@ public: { return dumb_ptr<T>(new T(std::forward<A>(a)...)); } - void forget() + dumb_ptr& operator = (std::nullptr_t) { impl = nullptr; + return *this; } T& operator *() const @@ -74,6 +84,15 @@ public: { return !impl; } + + friend bool operator == (dumb_ptr l, dumb_ptr r) + { + return l.impl == r.impl; + } + friend bool operator != (dumb_ptr l, dumb_ptr r) + { + return !(l == r); + } }; // unmanaged new/delete-able pointer @@ -85,6 +104,8 @@ class dumb_ptr<T[]> size_t sz; public: dumb_ptr() : impl(), sz() {} + dumb_ptr(std::nullptr_t) + : impl(nullptr), sz(0) {} dumb_ptr(T *p, size_t z) : impl(p) , sz(z) @@ -93,7 +114,7 @@ public: void delete_() { delete[] impl; - forget(); + *this = nullptr; } void new_(size_t z) { @@ -105,10 +126,11 @@ public: { return dumb_ptr<T[]>(new T[z](), z); } - void forget() + dumb_ptr& operator = (std::nullptr_t) { impl = nullptr; sz = 0; + return *this; } size_t size() const @@ -143,6 +165,15 @@ public: { return !impl; } + + friend bool operator == (dumb_ptr l, dumb_ptr r) + { + return l.impl == r.impl; + } + friend bool operator != (dumb_ptr l, dumb_ptr r) + { + return !(l == r); + } }; #endif // TMWA_COMMON_DUMB_PTR_HPP diff --git a/src/common/nullpo.hpp b/src/common/nullpo.hpp index 305448f..9eb9ea9 100644 --- a/src/common/nullpo.hpp +++ b/src/common/nullpo.hpp @@ -27,4 +27,15 @@ bool nullpo_chk(const char *file, int line, const char *func, const void *target); +template<class T> +bool nullpo_chk(const char *file, int line, const char *func, T target) +{ + return nullpo_chk(file, line, func, target.operator->()); +} +template<class T> +bool nullpo_chk(const char *file, int line, const char *func, T *target) +{ + return nullpo_chk(file, line, func, static_cast<const void *>(target)); +} + #endif // NULLPO_HPP diff --git a/src/common/timer.cpp b/src/common/timer.cpp index d2d355b..ec1f6b2 100644 --- a/src/common/timer.cpp +++ b/src/common/timer.cpp @@ -75,14 +75,14 @@ void Timer::cancel() td->owner = nullptr; td->func = do_nothing; td->interval = interval_t::zero(); - td.forget(); + td = nullptr; } void Timer::detach() { assert (this == td->owner); td->owner = nullptr; - td.forget(); + td = nullptr; } static @@ -116,7 +116,7 @@ Timer::Timer(tick_t tick, timer_func func, interval_t interval) Timer::Timer(Timer&& t) : td(t.td) { - t.td.forget(); + t.td = nullptr; if (td) { assert (td->owner == &t); diff --git a/src/map/atcommand.cpp b/src/map/atcommand.cpp index 207ce25..56ff2ab 100644 --- a/src/map/atcommand.cpp +++ b/src/map/atcommand.cpp @@ -32,7 +32,7 @@ #include "../poison.hpp" #define ATCOMMAND_FUNC(x) static \ -int atcommand_##x(const int fd, struct map_session_data* sd, const char* command, const char* message) +int atcommand_##x(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) ATCOMMAND_FUNC(setup); ATCOMMAND_FUNC(broadcast); ATCOMMAND_FUNC(localbroadcast); @@ -182,14 +182,15 @@ struct AtCommandInfo { const char *command; int level; - int(*proc)(const int, struct map_session_data *, + int(*proc)(const int, dumb_ptr<map_session_data>, const char *command, const char *message); }; // First char of commands is configured in atcommand_athena.conf. Leave @ in this list for default value. // to set default level, read atcommand_athena.conf first please. static -AtCommandInfo atcommand_info[] = { +AtCommandInfo atcommand_info[] = +{ {"@setup", 40, atcommand_setup}, {"@charwarp", 60, atcommand_charwarp}, {"@warp", 40, atcommand_warp}, @@ -362,7 +363,7 @@ FILE *get_gm_log(); /*======================================== * At-command logging */ -void log_atcommand(struct map_session_data *sd, const_string cmd) +void log_atcommand(dumb_ptr<map_session_data> sd, const_string cmd) { FILE *fp = get_gm_log(); if (!fp) @@ -420,7 +421,7 @@ AtCommandInfo *atcommand(const int level, const char *message); *is_atcommand @コマンドに存在するかどうか確認する *------------------------------------------ */ -bool is_atcommand(const int fd, struct map_session_data *sd, +bool is_atcommand(const int fd, dumb_ptr<map_session_data> sd, const char *message, int gmlvl) { nullpo_retr(false, sd); @@ -510,15 +511,15 @@ AtCommandInfo *atcommand(const int level, const char *message) *------------------------------------------ */ static -void atkillmonster_sub(struct block_list *bl, int flag) +void atkillmonster_sub(dumb_ptr<block_list> bl, int flag) { nullpo_retv(bl); + dumb_ptr<mob_data> md = bl->as_mob(); if (flag) - mob_damage(NULL, (struct mob_data *) bl, - ((struct mob_data *) bl)->hp, 2); + mob_damage(NULL, md, md->hp, 2); else - mob_delete((struct mob_data *) bl); + mob_delete(md); } /*========================================== @@ -588,7 +589,7 @@ int atcommand_config_read(const char *cfgName) * TAW Specific *------------------------------------------ */ -int atcommand_setup(const int fd, struct map_session_data *sd, +int atcommand_setup(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { char character[100]; @@ -634,13 +635,13 @@ int atcommand_setup(const int fd, struct map_session_data *sd, * @rura+ *------------------------------------------ */ -int atcommand_charwarp(const int fd, struct map_session_data *sd, +int atcommand_charwarp(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { char map_name[100]; char character[100]; int x = 0, y = 0; - struct map_session_data *pl_sd; + dumb_ptr<map_session_data> pl_sd; int m; memset(map_name, '\0', sizeof(map_name)); @@ -719,7 +720,7 @@ int atcommand_charwarp(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_warp(const int fd, struct map_session_data *sd, +int atcommand_warp(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { char map_name[100]; @@ -782,11 +783,11 @@ int atcommand_warp(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_where(const int fd, struct map_session_data *sd, +int atcommand_where(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { char character[100]; - struct map_session_data *pl_sd; + dumb_ptr<map_session_data> pl_sd; memset(character, '\0', sizeof(character)); @@ -816,11 +817,11 @@ int atcommand_where(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_goto(const int fd, struct map_session_data *sd, +int atcommand_goto(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { char character[100]; - struct map_session_data *pl_sd; + dumb_ptr<map_session_data> pl_sd; memset(character, '\0', sizeof(character)); @@ -864,7 +865,7 @@ int atcommand_goto(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_jump(const int fd, struct map_session_data *sd, +int atcommand_jump(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { int x = 0, y = 0; @@ -907,7 +908,7 @@ int atcommand_jump(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_who(const int fd, struct map_session_data *sd, +int atcommand_who(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { int count; @@ -929,7 +930,7 @@ int atcommand_who(const int fd, struct map_session_data *sd, { if (!session[i]) continue; - map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + dumb_ptr<map_session_data> pl_sd = dumb_ptr<map_session_data>(static_cast<map_session_data *>(session[i]->session_data.get())); if (pl_sd && pl_sd->state.auth) { pl_GM_level = pc_isGM(pl_sd); @@ -980,7 +981,7 @@ int atcommand_who(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_whogroup(const int fd, struct map_session_data *sd, +int atcommand_whogroup(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { int count; @@ -1003,7 +1004,7 @@ int atcommand_whogroup(const int fd, struct map_session_data *sd, { if (!session[i]) continue; - map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + dumb_ptr<map_session_data> pl_sd = dumb_ptr<map_session_data>(static_cast<map_session_data *>(session[i]->session_data.get())); if (pl_sd && pl_sd->state.auth) { pl_GM_level = pc_isGM(pl_sd); @@ -1050,7 +1051,7 @@ int atcommand_whogroup(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_whomap(const int fd, struct map_session_data *sd, +int atcommand_whomap(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { int count; @@ -1077,7 +1078,7 @@ int atcommand_whomap(const int fd, struct map_session_data *sd, { if (!session[i]) continue; - map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + dumb_ptr<map_session_data> pl_sd = dumb_ptr<map_session_data>(static_cast<map_session_data *>(session[i]->session_data.get())); if (pl_sd && pl_sd->state.auth) { pl_GM_level = pc_isGM(pl_sd); @@ -1117,7 +1118,7 @@ int atcommand_whomap(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_whomapgroup(const int fd, struct map_session_data *sd, +int atcommand_whomapgroup(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { int count; @@ -1145,7 +1146,7 @@ int atcommand_whomapgroup(const int fd, struct map_session_data *sd, { if (!session[i]) continue; - map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + dumb_ptr<map_session_data> pl_sd = dumb_ptr<map_session_data>(static_cast<map_session_data *>(session[i]->session_data.get())); if (pl_sd && pl_sd->state.auth) { pl_GM_level = pc_isGM(pl_sd); @@ -1191,7 +1192,7 @@ int atcommand_whomapgroup(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_whogm(const int fd, struct map_session_data *sd, +int atcommand_whogm(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { int count; @@ -1214,7 +1215,7 @@ int atcommand_whogm(const int fd, struct map_session_data *sd, { if (!session[i]) continue; - map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + dumb_ptr<map_session_data> pl_sd = dumb_ptr<map_session_data>(static_cast<map_session_data *>(session[i]->session_data.get())); if (pl_sd && pl_sd->state.auth) { pl_GM_level = pc_isGM(pl_sd); @@ -1274,7 +1275,7 @@ int atcommand_whogm(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_save(const int fd, struct map_session_data *sd, +int atcommand_save(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *) { nullpo_retr(-1, sd); @@ -1291,7 +1292,7 @@ int atcommand_save(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_load(const int fd, struct map_session_data *sd, +int atcommand_load(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *) { int m; @@ -1323,7 +1324,7 @@ int atcommand_load(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_speed(const int fd, struct map_session_data *sd, +int atcommand_speed(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { if (!message || !*message) @@ -1362,7 +1363,7 @@ int atcommand_speed(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_storage(const int fd, struct map_session_data *sd, +int atcommand_storage(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *) { struct storage *stor; //changes from Freya/Yor @@ -1390,7 +1391,7 @@ int atcommand_storage(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_option(const int fd, struct map_session_data *sd, +int atcommand_option(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { int param1_ = 0, param2_ = 0, param3_ = 0; @@ -1424,7 +1425,7 @@ int atcommand_option(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_hide(const int fd, struct map_session_data *sd, +int atcommand_hide(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *) { if (bool(sd->status.option & Option::HIDE)) @@ -1446,7 +1447,7 @@ int atcommand_hide(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_die(const int fd, struct map_session_data *sd, +int atcommand_die(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *) { pc_damage(NULL, sd, sd->status.hp + 1); @@ -1459,11 +1460,11 @@ int atcommand_die(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_kill(const int fd, struct map_session_data *sd, +int atcommand_kill(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { char character[100]; - struct map_session_data *pl_sd; + dumb_ptr<map_session_data> pl_sd; memset(character, '\0', sizeof(character)); @@ -1500,7 +1501,7 @@ int atcommand_kill(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_alive(const int fd, struct map_session_data *sd, +int atcommand_alive(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *) { sd->status.hp = sd->status.max_hp; @@ -1520,7 +1521,7 @@ int atcommand_alive(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_kami(const int fd, struct map_session_data *, +int atcommand_kami(const int fd, dumb_ptr<map_session_data>, const char *, const char *message) { if (!message || !*message) @@ -1539,7 +1540,7 @@ int atcommand_kami(const int fd, struct map_session_data *, * *------------------------------------------ */ -int atcommand_heal(const int fd, struct map_session_data *sd, +int atcommand_heal(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { int hp = 0, sp = 0; // [Valaris] thanks to fov @@ -1587,7 +1588,7 @@ int atcommand_heal(const int fd, struct map_session_data *sd, * @item command (usage: @item <name/id_of_item> <quantity>) *------------------------------------------ */ -int atcommand_item(const int fd, struct map_session_data *sd, +int atcommand_item(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { char item_name[100]; @@ -1649,7 +1650,7 @@ int atcommand_item(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_itemreset(const int fd, struct map_session_data *sd, +int atcommand_itemreset(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *) { int i; @@ -1669,7 +1670,7 @@ int atcommand_itemreset(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_itemcheck(const int, struct map_session_data *sd, +int atcommand_itemcheck(const int, dumb_ptr<map_session_data> sd, const char *, const char *) { pc_checkitem(sd); @@ -1681,7 +1682,7 @@ int atcommand_itemcheck(const int, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_baselevelup(const int fd, struct map_session_data *sd, +int atcommand_baselevelup(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { int level, i; @@ -1747,7 +1748,7 @@ int atcommand_baselevelup(const int fd, struct map_session_data *sd, */ // TODO: merge this with pc_setparam(SP::JOBLEVEL) // then fix the funny 50 and/or 10 limitation. -int atcommand_joblevelup(const int fd, struct map_session_data *sd, +int atcommand_joblevelup(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { int up_level = 50, level; @@ -1809,7 +1810,7 @@ int atcommand_joblevelup(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_help(const int fd, struct map_session_data *sd, +int atcommand_help(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *) { char buf[2048], w1[2048], w2[2048]; @@ -1854,7 +1855,7 @@ int atcommand_help(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_gm(const int fd, struct map_session_data *sd, +int atcommand_gm(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { char password[100]; @@ -1884,7 +1885,7 @@ int atcommand_gm(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_pvpoff(const int fd, struct map_session_data *sd, +int atcommand_pvpoff(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *) { if (battle_config.pk_mode) @@ -1900,7 +1901,7 @@ int atcommand_pvpoff(const int fd, struct map_session_data *sd, { if (!session[i]) continue; - map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + dumb_ptr<map_session_data> pl_sd = dumb_ptr<map_session_data>(static_cast<map_session_data *>(session[i]->session_data.get())); if (pl_sd && pl_sd->state.auth) { if (sd->bl_m == pl_sd->bl_m) @@ -1924,7 +1925,7 @@ int atcommand_pvpoff(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_pvpon(const int fd, struct map_session_data *sd, +int atcommand_pvpon(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *) { if (battle_config.pk_mode) @@ -1940,7 +1941,7 @@ int atcommand_pvpon(const int fd, struct map_session_data *sd, { if (!session[i]) continue; - map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + dumb_ptr<map_session_data> pl_sd = dumb_ptr<map_session_data>(static_cast<map_session_data *>(session[i]->session_data.get())); if (pl_sd && pl_sd->state.auth) { if (sd->bl_m == pl_sd->bl_m && !pl_sd->pvp_timer) @@ -1968,7 +1969,7 @@ int atcommand_pvpon(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_model(const int fd, struct map_session_data *sd, +int atcommand_model(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { int hair_style = 0, hair_color = 0, cloth_color = 0; @@ -2010,7 +2011,7 @@ int atcommand_model(const int fd, struct map_session_data *sd, * @dye && @ccolor *------------------------------------------ */ -int atcommand_dye(const int fd, struct map_session_data *sd, +int atcommand_dye(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { int cloth_color = 0; @@ -2044,7 +2045,7 @@ int atcommand_dye(const int fd, struct map_session_data *sd, * @hairstyle && @hstyle *------------------------------------------ */ -int atcommand_hair_style(const int fd, struct map_session_data *sd, +int atcommand_hair_style(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { int hair_style = 0; @@ -2078,7 +2079,7 @@ int atcommand_hair_style(const int fd, struct map_session_data *sd, * @haircolor && @hcolor *------------------------------------------ */ -int atcommand_hair_color(const int fd, struct map_session_data *sd, +int atcommand_hair_color(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { int hair_color = 0; @@ -2112,7 +2113,7 @@ int atcommand_hair_color(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_spawn(const int fd, struct map_session_data *sd, +int atcommand_spawn(const int fd, dumb_ptr<map_session_data> sd, const char *command, const char *message) { char monster[100]; @@ -2206,7 +2207,7 @@ int atcommand_spawn(const int fd, struct map_session_data *sd, *------------------------------------------ */ static -void atcommand_killmonster_sub(const int fd, struct map_session_data *sd, +void atcommand_killmonster_sub(const int fd, dumb_ptr<map_session_data> sd, const char *message, const int drop) { int map_id; @@ -2236,7 +2237,7 @@ void atcommand_killmonster_sub(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_killmonster(const int fd, struct map_session_data *sd, +int atcommand_killmonster(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { atcommand_killmonster_sub(fd, sd, message, 1); @@ -2249,12 +2250,12 @@ int atcommand_killmonster(const int fd, struct map_session_data *sd, *------------------------------------------ */ static -void atlist_nearby_sub(struct block_list *bl, int fd) +void atlist_nearby_sub(dumb_ptr<block_list> bl, int fd) { nullpo_retv(bl); std::string buf = STRPRINTF(" - \"%s\"", - ((struct map_session_data *) bl)->status.name); + bl->as_player()->status.name); clif_displaymessage(fd, buf); } @@ -2262,7 +2263,7 @@ void atlist_nearby_sub(struct block_list *bl, int fd) * *------------------------------------------ */ -int atcommand_list_nearby(const int fd, struct map_session_data *sd, +int atcommand_list_nearby(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *) { clif_displaymessage(fd, "Nearby players:"); @@ -2277,7 +2278,7 @@ int atcommand_list_nearby(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_killmonster2(const int fd, struct map_session_data *sd, +int atcommand_killmonster2(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { atcommand_killmonster_sub(fd, sd, message, 0); @@ -2289,7 +2290,7 @@ int atcommand_killmonster2(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_gat(const int fd, struct map_session_data *sd, +int atcommand_gat(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *) { int y; @@ -2314,7 +2315,7 @@ int atcommand_gat(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_packet(const int fd, struct map_session_data *sd, +int atcommand_packet(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { int type = 0, flag = 0; @@ -2335,7 +2336,7 @@ int atcommand_packet(const int fd, struct map_session_data *sd, * @stpoint (Rewritten by [Yor]) *------------------------------------------ */ -int atcommand_statuspoint(const int fd, struct map_session_data *sd, +int atcommand_statuspoint(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { int point, new_status_point; @@ -2375,7 +2376,7 @@ int atcommand_statuspoint(const int fd, struct map_session_data *sd, * @skpoint (Rewritten by [Yor]) *------------------------------------------ */ -int atcommand_skillpoint(const int fd, struct map_session_data *sd, +int atcommand_skillpoint(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { int point, new_skill_point; @@ -2415,7 +2416,7 @@ int atcommand_skillpoint(const int fd, struct map_session_data *sd, * @zeny (Rewritten by [Yor]) *------------------------------------------ */ -int atcommand_zeny(const int fd, struct map_session_data *sd, +int atcommand_zeny(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { int zeny, new_zeny; @@ -2456,7 +2457,7 @@ int atcommand_zeny(const int fd, struct map_session_data *sd, *------------------------------------------ */ template<ATTR attr> -int atcommand_param(const int fd, struct map_session_data *sd, +int atcommand_param(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { int value = 0, new_value; @@ -2503,7 +2504,7 @@ int atcommand_param(const int fd, struct map_session_data *sd, *------------------------------------------ */ //** Stat all by fritz (rewritten by [Yor]) -int atcommand_all_stats(const int fd, struct map_session_data *sd, +int atcommand_all_stats(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { int count, value = 0, new_value; @@ -2549,11 +2550,11 @@ int atcommand_all_stats(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_recall(const int fd, struct map_session_data *sd, +int atcommand_recall(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { char character[100]; - struct map_session_data *pl_sd; + dumb_ptr<map_session_data> pl_sd; memset(character, '\0', sizeof(character)); @@ -2605,11 +2606,11 @@ int atcommand_recall(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_revive(const int fd, struct map_session_data *sd, +int atcommand_revive(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { char character[100]; - struct map_session_data *pl_sd; + dumb_ptr<map_session_data> pl_sd; memset(character, '\0', sizeof(character)); @@ -2644,11 +2645,11 @@ int atcommand_revive(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_character_stats(const int fd, struct map_session_data *, +int atcommand_character_stats(const int fd, dumb_ptr<map_session_data>, const char *, const char *message) { char character[100]; - struct map_session_data *pl_sd; + dumb_ptr<map_session_data> pl_sd; memset(character, '\0', sizeof(character)); @@ -2705,7 +2706,7 @@ int atcommand_character_stats(const int fd, struct map_session_data *, *------------------------------------------ */ //** Character Stats All by fritz -int atcommand_character_stats_all(const int fd, struct map_session_data *, +int atcommand_character_stats_all(const int fd, dumb_ptr<map_session_data>, const char *, const char *) { int count; @@ -2715,7 +2716,7 @@ int atcommand_character_stats_all(const int fd, struct map_session_data *, { if (!session[i]) continue; - map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + dumb_ptr<map_session_data> pl_sd = dumb_ptr<map_session_data>(static_cast<map_session_data *>(session[i]->session_data.get())); if (pl_sd && pl_sd->state.auth) { std::string gmlevel; @@ -2764,12 +2765,12 @@ int atcommand_character_stats_all(const int fd, struct map_session_data *, * *------------------------------------------ */ -int atcommand_character_option(const int fd, struct map_session_data *sd, +int atcommand_character_option(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { char character[100]; int opt1_ = 0, opt2_ = 0, opt3_ = 0; - struct map_session_data *pl_sd; + dumb_ptr<map_session_data> pl_sd; memset(character, '\0', sizeof(character)); @@ -2818,7 +2819,7 @@ int atcommand_character_option(const int fd, struct map_session_data *sd, * charchangesex command (usage: charchangesex <player_name>) *------------------------------------------ */ -int atcommand_char_change_sex(const int fd, struct map_session_data *sd, +int atcommand_char_change_sex(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { char character[100]; @@ -2857,7 +2858,7 @@ int atcommand_char_change_sex(const int fd, struct map_session_data *sd, * This command do a definitiv ban on a player *------------------------------------------ */ -int atcommand_char_block(const int fd, struct map_session_data *sd, +int atcommand_char_block(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { char character[100]; @@ -2907,7 +2908,7 @@ int atcommand_char_block(const int fd, struct map_session_data *sd, * this example adds 1 month and 1 second, and substracts 2 minutes and 6 years at the same time. *------------------------------------------ */ -int atcommand_char_ban(const int fd, struct map_session_data *sd, +int atcommand_char_ban(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { char modif[100], character[100]; @@ -3008,7 +3009,7 @@ int atcommand_char_ban(const int fd, struct map_session_data *sd, * charunblock command (usage: charunblock <player_name>) *------------------------------------------ */ -int atcommand_char_unblock(const int fd, struct map_session_data *sd, +int atcommand_char_unblock(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { char character[100]; @@ -3047,7 +3048,7 @@ int atcommand_char_unblock(const int fd, struct map_session_data *sd, * charunban command (usage: charunban <player_name>) *------------------------------------------ */ -int atcommand_char_unban(const int fd, struct map_session_data *sd, +int atcommand_char_unban(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { char character[100]; @@ -3086,12 +3087,12 @@ int atcommand_char_unban(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_character_save(const int fd, struct map_session_data *sd, +int atcommand_character_save(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { char map_name[100]; char character[100]; - struct map_session_data *pl_sd; + dumb_ptr<map_session_data> pl_sd; int x = 0, y = 0; int m; @@ -3152,14 +3153,14 @@ int atcommand_character_save(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_doom(const int fd, struct map_session_data *sd, +int atcommand_doom(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *) { for (int i = 0; i < fd_max; i++) { if (!session[i]) continue; - map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + dumb_ptr<map_session_data> pl_sd = dumb_ptr<map_session_data>(static_cast<map_session_data *>(session[i]->session_data.get())); if (pl_sd && pl_sd->state.auth && i != fd && pc_isGM(sd) >= pc_isGM(pl_sd)) @@ -3177,14 +3178,14 @@ int atcommand_doom(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_doommap(const int fd, struct map_session_data *sd, +int atcommand_doommap(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *) { for (int i = 0; i < fd_max; i++) { if (!session[i]) continue; - map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + dumb_ptr<map_session_data> pl_sd = dumb_ptr<map_session_data>(static_cast<map_session_data *>(session[i]->session_data.get())); if (pl_sd && pl_sd->state.auth && i != fd && sd->bl_m == pl_sd->bl_m && pc_isGM(sd) >= pc_isGM(pl_sd)) @@ -3203,7 +3204,7 @@ int atcommand_doommap(const int fd, struct map_session_data *sd, *------------------------------------------ */ static -void atcommand_raise_sub(struct map_session_data *sd) +void atcommand_raise_sub(dumb_ptr<map_session_data> sd) { if (sd && sd->state.auth && pc_isdead(sd)) { @@ -3221,14 +3222,14 @@ void atcommand_raise_sub(struct map_session_data *sd) * *------------------------------------------ */ -int atcommand_raise(const int fd, struct map_session_data *, +int atcommand_raise(const int fd, dumb_ptr<map_session_data>, const char *, const char *) { for (int i = 0; i < fd_max; i++) { if (!session[i]) continue; - map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + dumb_ptr<map_session_data> pl_sd = dumb_ptr<map_session_data>(static_cast<map_session_data *>(session[i]->session_data.get())); atcommand_raise_sub(pl_sd); } clif_displaymessage(fd, "Mercy has been granted."); @@ -3240,14 +3241,14 @@ int atcommand_raise(const int fd, struct map_session_data *, * *------------------------------------------ */ -int atcommand_raisemap(const int fd, struct map_session_data *sd, +int atcommand_raisemap(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *) { for (int i = 0; i < fd_max; i++) { if (!session[i]) continue; - map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + dumb_ptr<map_session_data> pl_sd = dumb_ptr<map_session_data>(static_cast<map_session_data *>(session[i]->session_data.get())); if (pl_sd && pl_sd->state.auth && sd->bl_m == pl_sd->bl_m) atcommand_raise_sub(pl_sd); @@ -3261,10 +3262,10 @@ int atcommand_raisemap(const int fd, struct map_session_data *sd, * atcommand_character_baselevel @charbaselvlで対象キャラのレベルを上げる *------------------------------------------ */ -int atcommand_character_baselevel(const int fd, struct map_session_data *sd, +int atcommand_character_baselevel(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { - struct map_session_data *pl_sd; + dumb_ptr<map_session_data> pl_sd; char character[100]; int level = 0, i; @@ -3355,10 +3356,10 @@ int atcommand_character_baselevel(const int fd, struct map_session_data *sd, * atcommand_character_joblevel @charjoblvlで対象キャラのJobレベルを上げる *------------------------------------------ */ -int atcommand_character_joblevel(const int fd, struct map_session_data *sd, +int atcommand_character_joblevel(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { - struct map_session_data *pl_sd; + dumb_ptr<map_session_data> pl_sd; char character[100]; int max_level = 50, level = 0; @@ -3440,10 +3441,10 @@ int atcommand_character_joblevel(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_kick(const int fd, struct map_session_data *sd, +int atcommand_kick(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { - struct map_session_data *pl_sd; + dumb_ptr<map_session_data> pl_sd; char character[100]; memset(character, '\0', sizeof(character)); @@ -3478,14 +3479,14 @@ int atcommand_kick(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_kickall(const int fd, struct map_session_data *sd, +int atcommand_kickall(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *) { for (int i = 0; i < fd_max; i++) { if (!session[i]) continue; - map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + dumb_ptr<map_session_data> pl_sd = dumb_ptr<map_session_data>(static_cast<map_session_data *>(session[i]->session_data.get())); if (pl_sd && pl_sd->state.auth && pc_isGM(sd) >= pc_isGM(pl_sd)) { @@ -3504,7 +3505,7 @@ int atcommand_kickall(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_questskill(const int fd, struct map_session_data *sd, +int atcommand_questskill(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { int skill_id_; @@ -3552,11 +3553,11 @@ int atcommand_questskill(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_charquestskill(const int fd, struct map_session_data *, +int atcommand_charquestskill(const int fd, dumb_ptr<map_session_data>, const char *, const char *message) { char character[100]; - struct map_session_data *pl_sd; + dumb_ptr<map_session_data> pl_sd; int skill_id_ = 0; memset(character, '\0', sizeof(character)); @@ -3614,7 +3615,7 @@ int atcommand_charquestskill(const int fd, struct map_session_data *, * *------------------------------------------ */ -int atcommand_lostskill(const int fd, struct map_session_data *sd, +int atcommand_lostskill(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { int skill_id_; @@ -3664,11 +3665,11 @@ int atcommand_lostskill(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_charlostskill(const int fd, struct map_session_data *, +int atcommand_charlostskill(const int fd, dumb_ptr<map_session_data>, const char *, const char *message) { char character[100]; - struct map_session_data *pl_sd; + dumb_ptr<map_session_data> pl_sd; int skill_id_ = 0; memset(character, '\0', sizeof(character)); @@ -3728,7 +3729,7 @@ int atcommand_charlostskill(const int fd, struct map_session_data *, * *------------------------------------------ */ -int atcommand_party(const int fd, struct map_session_data *sd, +int atcommand_party(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { char party[100]; @@ -3751,14 +3752,14 @@ int atcommand_party(const int fd, struct map_session_data *sd, * @mapexitでマップサーバーを終了させる *------------------------------------------ */ -int atcommand_mapexit(const int, struct map_session_data *sd, +int atcommand_mapexit(const int, dumb_ptr<map_session_data> sd, const char *, const char *) { for (int i = 0; i < fd_max; i++) { if (!session[i]) continue; - map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + dumb_ptr<map_session_data> pl_sd = dumb_ptr<map_session_data>(static_cast<map_session_data *>(session[i]->session_data.get())); if (pl_sd && pl_sd->state.auth) { if (sd->status.account_id != pl_sd->status.account_id) @@ -3776,7 +3777,7 @@ int atcommand_mapexit(const int, struct map_session_data *sd, * idsearch <part_of_name>: revrited by [Yor] *------------------------------------------ */ -int atcommand_idsearch(const int fd, struct map_session_data *, +int atcommand_idsearch(const int fd, dumb_ptr<map_session_data>, const char *, const char *message) { char item_name[100]; @@ -3815,11 +3816,11 @@ int atcommand_idsearch(const int fd, struct map_session_data *, * Character Skill Reset *------------------------------------------ */ -int atcommand_charskreset(const int fd, struct map_session_data *sd, +int atcommand_charskreset(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { char character[100]; - struct map_session_data *pl_sd; + dumb_ptr<map_session_data> pl_sd; memset(character, '\0', sizeof(character)); @@ -3858,11 +3859,11 @@ int atcommand_charskreset(const int fd, struct map_session_data *sd, * Character Stat Reset *------------------------------------------ */ -int atcommand_charstreset(const int fd, struct map_session_data *sd, +int atcommand_charstreset(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { char character[100]; - struct map_session_data *pl_sd; + dumb_ptr<map_session_data> pl_sd; memset(character, '\0', sizeof(character)); @@ -3902,11 +3903,11 @@ int atcommand_charstreset(const int fd, struct map_session_data *sd, * Character Reset *------------------------------------------ */ -int atcommand_charreset(const int fd, struct map_session_data *sd, +int atcommand_charreset(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { char character[100]; - struct map_session_data *pl_sd; + dumb_ptr<map_session_data> pl_sd; memset(character, '\0', sizeof(character)); @@ -3948,11 +3949,11 @@ int atcommand_charreset(const int fd, struct map_session_data *sd, * Character Wipe *------------------------------------------ */ -int atcommand_char_wipe(const int fd, struct map_session_data *sd, +int atcommand_char_wipe(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { char character[100]; - struct map_session_data *pl_sd; + dumb_ptr<map_session_data> pl_sd; memset(character, '\0', sizeof(character)); @@ -4036,11 +4037,11 @@ int atcommand_char_wipe(const int fd, struct map_session_data *sd, * Character Model by chbrules *------------------------------------------ */ -int atcommand_charmodel(const int fd, struct map_session_data *, +int atcommand_charmodel(const int fd, dumb_ptr<map_session_data>, const char *, const char *message) { int hair_style = 0, hair_color = 0, cloth_color = 0; - struct map_session_data *pl_sd; + dumb_ptr<map_session_data> pl_sd; char character[100]; memset(character, '\0', sizeof(character)); @@ -4091,10 +4092,10 @@ int atcommand_charmodel(const int fd, struct map_session_data *, * Character Skill Point (Rewritten by [Yor]) *------------------------------------------ */ -int atcommand_charskpoint(const int fd, struct map_session_data *, +int atcommand_charskpoint(const int fd, dumb_ptr<map_session_data>, const char *, const char *message) { - struct map_session_data *pl_sd; + dumb_ptr<map_session_data> pl_sd; char character[100]; int new_skill_point; int point = 0; @@ -4145,10 +4146,10 @@ int atcommand_charskpoint(const int fd, struct map_session_data *, * Character Status Point (rewritten by [Yor]) *------------------------------------------ */ -int atcommand_charstpoint(const int fd, struct map_session_data *, +int atcommand_charstpoint(const int fd, dumb_ptr<map_session_data>, const char *, const char *message) { - struct map_session_data *pl_sd; + dumb_ptr<map_session_data> pl_sd; char character[100]; int new_status_point; int point = 0; @@ -4199,10 +4200,10 @@ int atcommand_charstpoint(const int fd, struct map_session_data *, * Character Zeny Point (Rewritten by [Yor]) *------------------------------------------ */ -int atcommand_charzeny(const int fd, struct map_session_data *, +int atcommand_charzeny(const int fd, dumb_ptr<map_session_data>, const char *, const char *message) { - struct map_session_data *pl_sd; + dumb_ptr<map_session_data> pl_sd; char character[100]; int zeny = 0, new_zeny; @@ -4251,7 +4252,7 @@ int atcommand_charzeny(const int fd, struct map_session_data *, * Recall All Characters Online To Your Location *------------------------------------------ */ -int atcommand_recallall(const int fd, struct map_session_data *sd, +int atcommand_recallall(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *) { int count; @@ -4269,7 +4270,7 @@ int atcommand_recallall(const int fd, struct map_session_data *sd, { if (!session[i]) continue; - map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + dumb_ptr<map_session_data> pl_sd = dumb_ptr<map_session_data>(static_cast<map_session_data *>(session[i]->session_data.get())); if (pl_sd && pl_sd->state.auth && sd->status.account_id != pl_sd->status.account_id @@ -4300,7 +4301,7 @@ int atcommand_recallall(const int fd, struct map_session_data *sd, * Recall online characters of a party to your location *------------------------------------------ */ -int atcommand_partyrecall(const int fd, struct map_session_data *sd, +int atcommand_partyrecall(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { char party_name[100]; @@ -4332,7 +4333,7 @@ int atcommand_partyrecall(const int fd, struct map_session_data *sd, { if (!session[i]) continue; - map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + dumb_ptr<map_session_data> pl_sd = dumb_ptr<map_session_data>(static_cast<map_session_data *>(session[i]->session_data.get())); if (pl_sd && pl_sd->state.auth && sd->status.account_id != pl_sd->status.account_id && pl_sd->status.party_id == p->party_id) @@ -4367,7 +4368,7 @@ int atcommand_partyrecall(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_reloaditemdb(const int fd, struct map_session_data *, +int atcommand_reloaditemdb(const int fd, dumb_ptr<map_session_data>, const char *, const char *) { itemdb_reload(); @@ -4380,7 +4381,7 @@ int atcommand_reloaditemdb(const int fd, struct map_session_data *, * *------------------------------------------ */ -int atcommand_reloadmobdb(const int fd, struct map_session_data *, +int atcommand_reloadmobdb(const int fd, dumb_ptr<map_session_data>, const char *, const char *) { mob_reload(); @@ -4393,7 +4394,7 @@ int atcommand_reloadmobdb(const int fd, struct map_session_data *, * *------------------------------------------ */ -int atcommand_reloadskilldb(const int fd, struct map_session_data *, +int atcommand_reloadskilldb(const int fd, dumb_ptr<map_session_data>, const char *, const char *) { skill_reload(); @@ -4406,7 +4407,7 @@ int atcommand_reloadskilldb(const int fd, struct map_session_data *, * *------------------------------------------ */ -int atcommand_reloadscript(const int fd, struct map_session_data *, +int atcommand_reloadscript(const int fd, dumb_ptr<map_session_data>, const char *, const char *) { do_init_npc(); @@ -4423,7 +4424,7 @@ int atcommand_reloadscript(const int fd, struct map_session_data *, * *------------------------------------------ */ -int atcommand_reloadgmdb(const int fd, struct map_session_data *, +int atcommand_reloadgmdb(const int fd, dumb_ptr<map_session_data>, const char *, const char *) { chrif_reloadGMdb(); @@ -4441,10 +4442,10 @@ int atcommand_reloadgmdb(const int fd, struct map_session_data *, * 2 = Shows NPCs in that map *------------------------------------------ */ -int atcommand_mapinfo(const int fd, struct map_session_data *sd, +int atcommand_mapinfo(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { - struct npc_data *nd = NULL; + dumb_ptr<npc_data> nd = NULL; char map_name[100]; const char *direction = NULL; int m_id, list = 0; @@ -4519,7 +4520,7 @@ int atcommand_mapinfo(const int fd, struct map_session_data *sd, { if (!session[i]) continue; - map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + dumb_ptr<map_session_data> pl_sd = dumb_ptr<map_session_data>(static_cast<map_session_data *>(session[i]->session_data.get())); if (pl_sd && pl_sd->state.auth && strcmp(pl_sd->mapname, map_name) == 0) { @@ -4590,7 +4591,7 @@ int atcommand_mapinfo(const int fd, struct map_session_data *sd, *Spy Commands by Syrus22 *------------------------------------------ */ -int atcommand_partyspy(const int fd, struct map_session_data *sd, +int atcommand_partyspy(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { char party_name[100]; @@ -4634,7 +4635,7 @@ int atcommand_partyspy(const int fd, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_enablenpc(const int fd, struct map_session_data *, +int atcommand_enablenpc(const int fd, dumb_ptr<map_session_data>, const char *, const char *message) { char NPCname[100]; @@ -4666,7 +4667,7 @@ int atcommand_enablenpc(const int fd, struct map_session_data *, * *------------------------------------------ */ -int atcommand_disablenpc(const int fd, struct map_session_data *, +int atcommand_disablenpc(const int fd, dumb_ptr<map_session_data>, const char *, const char *message) { char NPCname[100]; @@ -4699,7 +4700,7 @@ int atcommand_disablenpc(const int fd, struct map_session_data *, * Calculation management of GM modification (@day/@night GM commands) is done *------------------------------------------ */ -int atcommand_servertime(const int fd, struct map_session_data *, +int atcommand_servertime(const int fd, dumb_ptr<map_session_data>, const char *, const char *) { timestamp_seconds_buffer tsbuf; @@ -4722,10 +4723,10 @@ int atcommand_servertime(const int fd, struct map_session_data *, * Inspired from a old command created by RoVeRT *------------------------------------------ */ -int atcommand_chardelitem(const int fd, struct map_session_data *sd, +int atcommand_chardelitem(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { - struct map_session_data *pl_sd; + dumb_ptr<map_session_data> pl_sd; char character[100]; char item_name[100]; int i, number = 0, item_id, item_position, count; @@ -4806,7 +4807,7 @@ int atcommand_chardelitem(const int fd, struct map_session_data *sd, * @broadcast by [Valaris] *------------------------------------------ */ -int atcommand_broadcast(const int fd, struct map_session_data *sd, +int atcommand_broadcast(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { if (!message || !*message) @@ -4826,7 +4827,7 @@ int atcommand_broadcast(const int fd, struct map_session_data *sd, * @localbroadcast by [Valaris] *------------------------------------------ */ -int atcommand_localbroadcast(const int fd, struct map_session_data *sd, +int atcommand_localbroadcast(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { if (!message || !*message) @@ -4847,7 +4848,7 @@ int atcommand_localbroadcast(const int fd, struct map_session_data *sd, * @ignorelist by [Yor] *------------------------------------------ */ -int atcommand_ignorelist(const int fd, struct map_session_data *sd, +int atcommand_ignorelist(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *) { int count; @@ -4891,11 +4892,11 @@ int atcommand_ignorelist(const int fd, struct map_session_data *sd, * @charignorelist <player_name> by [Yor] *------------------------------------------ */ -int atcommand_charignorelist(const int fd, struct map_session_data *, +int atcommand_charignorelist(const int fd, dumb_ptr<map_session_data>, const char *, const char *message) { char character[100]; - struct map_session_data *pl_sd; + dumb_ptr<map_session_data> pl_sd; int count; int i; @@ -4968,11 +4969,11 @@ int atcommand_charignorelist(const int fd, struct map_session_data *, * @inall <player_name> by [Yor] *------------------------------------------ */ -int atcommand_inall(const int fd, struct map_session_data *sd, +int atcommand_inall(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { char character[100]; - struct map_session_data *pl_sd; + dumb_ptr<map_session_data> pl_sd; memset(character, '\0', sizeof(character)); @@ -5029,11 +5030,11 @@ int atcommand_inall(const int fd, struct map_session_data *sd, * @exall <player_name> by [Yor] *------------------------------------------ */ -int atcommand_exall(const int fd, struct map_session_data *sd, +int atcommand_exall(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { char character[100]; - struct map_session_data *pl_sd; + dumb_ptr<map_session_data> pl_sd; memset(character, '\0', sizeof(character)); @@ -5090,7 +5091,7 @@ int atcommand_exall(const int fd, struct map_session_data *sd, * @email <actual@email> <new@email> by [Yor] *------------------------------------------ */ -int atcommand_email(const int fd, struct map_session_data *sd, +int atcommand_email(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { char actual_email[100]; @@ -5140,7 +5141,7 @@ int atcommand_email(const int fd, struct map_session_data *sd, *@effect *------------------------------------------ */ -int atcommand_effect(const int fd, struct map_session_data *sd, +int atcommand_effect(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { int type = 0, flag = 0; @@ -5162,7 +5163,7 @@ int atcommand_effect(const int fd, struct map_session_data *sd, { if (!session[i]) continue; - map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + dumb_ptr<map_session_data> pl_sd = dumb_ptr<map_session_data>(static_cast<map_session_data *>(session[i]->session_data.get())); if (pl_sd && pl_sd->state.auth) { clif_specialeffect(pl_sd, type, flag); @@ -5178,10 +5179,10 @@ int atcommand_effect(const int fd, struct map_session_data *sd, * @charitemlist <character>: Displays the list of a player's items. *------------------------------------------ */ -int atcommand_character_item_list(const int fd, struct map_session_data *sd, +int atcommand_character_item_list(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { - struct map_session_data *pl_sd; + dumb_ptr<map_session_data> pl_sd; struct item_data *item_data, *item_temp; int i, j, count, counter, counter2; char character[100], equipstr[100]; @@ -5340,11 +5341,11 @@ int atcommand_character_item_list(const int fd, struct map_session_data *sd, * @charstoragelist <character>: Displays the items list of a player's storage. *------------------------------------------ */ -int atcommand_character_storage_list(const int fd, struct map_session_data *sd, +int atcommand_character_storage_list(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { struct storage *stor; - struct map_session_data *pl_sd; + dumb_ptr<map_session_data> pl_sd; struct item_data *item_data, *item_temp; int i, j, count, counter, counter2; char character[100]; @@ -5472,10 +5473,10 @@ int atcommand_character_storage_list(const int fd, struct map_session_data *sd, * @charcartlist <character>: Displays the items list of a player's cart. *------------------------------------------ */ -int atcommand_character_cart_list(const int fd, struct map_session_data *sd, +int atcommand_character_cart_list(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { - struct map_session_data *pl_sd; + dumb_ptr<map_session_data> pl_sd; struct item_data *item_data, *item_temp; int i, j, count, counter, counter2; char character[100]; @@ -5595,7 +5596,7 @@ int atcommand_character_cart_list(const int fd, struct map_session_data *sd, * enable killing players even when not in pvp *------------------------------------------ */ -int atcommand_killer(const int fd, struct map_session_data *sd, +int atcommand_killer(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *) { sd->special_state.killer = !sd->special_state.killer; @@ -5613,7 +5614,7 @@ int atcommand_killer(const int fd, struct map_session_data *sd, * enable other people killing you *------------------------------------------ */ -int atcommand_killable(const int fd, struct map_session_data *sd, +int atcommand_killable(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *) { sd->special_state.killable = !sd->special_state.killable; @@ -5631,10 +5632,10 @@ int atcommand_killable(const int fd, struct map_session_data *sd, * enable another player to be killed *------------------------------------------ */ -int atcommand_charkillable(const int fd, struct map_session_data *, +int atcommand_charkillable(const int fd, dumb_ptr<map_session_data>, const char *, const char *message) { - struct map_session_data *pl_sd = NULL; + dumb_ptr<map_session_data> pl_sd = NULL; if (!message || !*message) return -1; @@ -5658,12 +5659,12 @@ int atcommand_charkillable(const int fd, struct map_session_data *, * move a npc *------------------------------------------ */ -int atcommand_npcmove(const int, struct map_session_data *sd, +int atcommand_npcmove(const int, dumb_ptr<map_session_data> sd, const char *, const char *message) { char character[100]; int x = 0, y = 0; - struct npc_data *nd = 0; + dumb_ptr<npc_data> nd = 0; if (sd == NULL) return -1; @@ -5694,7 +5695,7 @@ int atcommand_npcmove(const int, struct map_session_data *sd, * Create a new static warp point. *------------------------------------------ */ -int atcommand_addwarp(const int fd, struct map_session_data *sd, +int atcommand_addwarp(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { char mapname[30]; @@ -5724,10 +5725,10 @@ int atcommand_addwarp(const int fd, struct map_session_data *sd, * Create a effect localized on another character *------------------------------------------ */ -int atcommand_chareffect(const int fd, struct map_session_data *, +int atcommand_chareffect(const int fd, dumb_ptr<map_session_data>, const char *, const char *message) { - struct map_session_data *pl_sd = NULL; + dumb_ptr<map_session_data> pl_sd = NULL; char target[255]; int type = 0; @@ -5753,7 +5754,7 @@ int atcommand_chareffect(const int fd, struct map_session_data *, * Drop all your possession on the ground *------------------------------------------ */ -int atcommand_dropall(const int, struct map_session_data *sd, +int atcommand_dropall(const int, dumb_ptr<map_session_data> sd, const char *, const char *) { int i; @@ -5776,11 +5777,11 @@ int atcommand_dropall(const int, struct map_session_data *sd, * done in response to them being disrespectful of a GM *------------------------------------------ */ -int atcommand_chardropall(const int fd, struct map_session_data *, +int atcommand_chardropall(const int fd, dumb_ptr<map_session_data>, const char *, const char *message) { int i; - struct map_session_data *pl_sd = NULL; + dumb_ptr<map_session_data> pl_sd = NULL; if (!message || !*message) return -1; @@ -5810,7 +5811,7 @@ int atcommand_chardropall(const int fd, struct map_session_data *, * debugging easie *------------------------------------------ */ -int atcommand_storeall(const int fd, struct map_session_data *sd, +int atcommand_storeall(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *) { int i; @@ -5850,11 +5851,11 @@ int atcommand_storeall(const int fd, struct map_session_data *sd, * A way to screw with players who piss you off *------------------------------------------ */ -int atcommand_charstoreall(const int fd, struct map_session_data *sd, +int atcommand_charstoreall(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { int i; - struct map_session_data *pl_sd = NULL; + dumb_ptr<map_session_data> pl_sd = NULL; if (!message || !*message) return -1; @@ -5894,7 +5895,7 @@ int atcommand_charstoreall(const int fd, struct map_session_data *sd, * It is made to rain. *------------------------------------------ */ -int atcommand_rain(const int, struct map_session_data *sd, +int atcommand_rain(const int, dumb_ptr<map_session_data> sd, const char *, const char *) { int effno = 0; @@ -5912,7 +5913,7 @@ int atcommand_rain(const int, struct map_session_data *sd, * It is made to snow. *------------------------------------------ */ -int atcommand_snow(const int, struct map_session_data *sd, +int atcommand_snow(const int, dumb_ptr<map_session_data> sd, const char *, const char *) { int effno = 0; @@ -5930,7 +5931,7 @@ int atcommand_snow(const int, struct map_session_data *sd, * Cherry tree snowstorm is made to fall. (Sakura) *------------------------------------------ */ -int atcommand_sakura(const int, struct map_session_data *sd, +int atcommand_sakura(const int, dumb_ptr<map_session_data> sd, const char *, const char *) { int effno = 0; @@ -5948,7 +5949,7 @@ int atcommand_sakura(const int, struct map_session_data *sd, * Fog hangs over. *------------------------------------------ */ -int atcommand_fog(const int, struct map_session_data *sd, +int atcommand_fog(const int, dumb_ptr<map_session_data> sd, const char *, const char *) { int effno = 0; @@ -5967,7 +5968,7 @@ int atcommand_fog(const int, struct map_session_data *sd, * Fallen leaves fall. *------------------------------------------ */ -int atcommand_leaves(const int, struct map_session_data *sd, +int atcommand_leaves(const int, dumb_ptr<map_session_data> sd, const char *, const char *) { int effno = 0; @@ -5985,7 +5986,7 @@ int atcommand_leaves(const int, struct map_session_data *sd, * *------------------------------------------ */ -int atcommand_summon(const int, struct map_session_data *sd, +int atcommand_summon(const int, dumb_ptr<map_session_data> sd, const char *, const char *message) { char name[100]; @@ -5993,7 +5994,7 @@ int atcommand_summon(const int, struct map_session_data *sd, int x = 0; int y = 0; int id = 0; - struct mob_data *md; + dumb_ptr<mob_data> md; tick_t tick = gettick(); nullpo_retr(-1, sd); @@ -6012,7 +6013,7 @@ int atcommand_summon(const int, struct map_session_data *sd, y = sd->bl_y + random_::in(-5, 4); id = mob_once_spawn(sd, "this", x, y, "--ja--", mob_id, 1, ""); - if ((md = (struct mob_data *) map_id2bl(id))) + if ((md = map_id_as_mob(id))) { md->master_id = sd->bl_id; md->state.special_mob_ai = 1; @@ -6035,7 +6036,7 @@ int atcommand_summon(const int, struct map_session_data *sd, * for short periods of time *------------------------------------------ */ -int atcommand_adjcmdlvl(const int fd, struct map_session_data *, +int atcommand_adjcmdlvl(const int fd, dumb_ptr<map_session_data>, const char *, const char *message) { int i, newlev; @@ -6068,12 +6069,12 @@ int atcommand_adjcmdlvl(const int fd, struct map_session_data *, * for short periods of time *------------------------------------------ */ -int atcommand_adjgmlvl(const int fd, struct map_session_data *, +int atcommand_adjgmlvl(const int fd, dumb_ptr<map_session_data>, const char *, const char *message) { int newlev; char user[100]; - struct map_session_data *pl_sd; + dumb_ptr<map_session_data> pl_sd; if (!message || !*message || sscanf(message, "%d %s", &newlev, user) != 2) @@ -6099,10 +6100,10 @@ int atcommand_adjgmlvl(const int fd, struct map_session_data *, * gonna scream! *------------------------------------------ */ -int atcommand_trade(const int, struct map_session_data *sd, +int atcommand_trade(const int, dumb_ptr<map_session_data> sd, const char *, const char *message) { - struct map_session_data *pl_sd = NULL; + dumb_ptr<map_session_data> pl_sd = NULL; if (!message || !*message) return -1; @@ -6141,11 +6142,11 @@ const char *magic_skill_names[magic_skills_nr] = "astral" }; -int atcommand_magic_info(const int fd, struct map_session_data *, +int atcommand_magic_info(const int fd, dumb_ptr<map_session_data>, const char *, const char *message) { char character[100]; - struct map_session_data *pl_sd; + dumb_ptr<map_session_data> pl_sd; memset(character, '\0', sizeof(character)); @@ -6182,18 +6183,18 @@ int atcommand_magic_info(const int fd, struct map_session_data *, } static -void set_skill(struct map_session_data *sd, SkillID i, int level) +void set_skill(dumb_ptr<map_session_data> sd, SkillID i, int level) { sd->status.skill[i].lv = level; } -int atcommand_set_magic(const int fd, struct map_session_data *, +int atcommand_set_magic(const int fd, dumb_ptr<map_session_data>, const char *, const char *message) { char character[100]; char magic_type[20]; int value; - struct map_session_data *pl_sd; + dumb_ptr<map_session_data> pl_sd; memset(character, '\0', sizeof(character)); @@ -6245,14 +6246,14 @@ int atcommand_set_magic(const int fd, struct map_session_data *, return -1; } -int atcommand_log(const int, struct map_session_data *, +int atcommand_log(const int, dumb_ptr<map_session_data>, const char *, const char *) { return 0; // only used for (implicit) logging } -int atcommand_tee(const int, struct map_session_data *sd, +int atcommand_tee(const int, dumb_ptr<map_session_data> sd, const char *, const char *message) { char data[strlen(message) + 28]; @@ -6263,14 +6264,14 @@ int atcommand_tee(const int, struct map_session_data *sd, return 0; } -int atcommand_invisible(const int, struct map_session_data *sd, +int atcommand_invisible(const int, dumb_ptr<map_session_data> sd, const char *, const char *) { pc_invisibility(sd, 1); return 0; } -int atcommand_visible(const int, struct map_session_data *sd, +int atcommand_visible(const int, dumb_ptr<map_session_data> sd, const char *, const char *) { pc_invisibility(sd, 0); @@ -6278,14 +6279,14 @@ int atcommand_visible(const int, struct map_session_data *sd, } static -int atcommand_jump_iterate(const int fd, struct map_session_data *sd, +int atcommand_jump_iterate(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *, - struct map_session_data *(*get_start)(void), - struct map_session_data *(*get_next)(struct map_session_data*)) + dumb_ptr<map_session_data> (*get_start)(void), + dumb_ptr<map_session_data> (*get_next)(dumb_ptr<map_session_data>)) { - struct map_session_data *pl_sd; + dumb_ptr<map_session_data> pl_sd; - pl_sd = (struct map_session_data *) map_id2bl(sd->followtarget); + pl_sd = map_id_as_player(sd->followtarget); if (pl_sd) pl_sd = get_next(pl_sd); @@ -6324,7 +6325,7 @@ int atcommand_jump_iterate(const int fd, struct map_session_data *sd, } int atcommand_iterate_forward_over_players(const int fd, - struct map_session_data *sd, + dumb_ptr<map_session_data> sd, const char *command, const char *message) { @@ -6334,7 +6335,7 @@ int atcommand_iterate_forward_over_players(const int fd, } int atcommand_iterate_backwards_over_players(const int fd, - struct map_session_data *sd, + dumb_ptr<map_session_data> sd, const char *command, const char *message) { @@ -6343,7 +6344,7 @@ int atcommand_iterate_backwards_over_players(const int fd, map_get_prev_session); } -int atcommand_wgm(const int fd, struct map_session_data *sd, +int atcommand_wgm(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *message) { if (tmw_CheckChatSpam(sd, message)) @@ -6357,11 +6358,11 @@ int atcommand_wgm(const int fd, struct map_session_data *sd, } -int atcommand_skillpool_info(const int fd, struct map_session_data *, +int atcommand_skillpool_info(const int fd, dumb_ptr<map_session_data>, const char *, const char *message) { char character[100]; - struct map_session_data *pl_sd; + dumb_ptr<map_session_data> pl_sd; if (!message || !*message || sscanf(message, "%99[^\n]", character) < 1) { @@ -6412,12 +6413,12 @@ int atcommand_skillpool_info(const int fd, struct map_session_data *, return 0; } -int atcommand_skillpool_focus(const int fd, struct map_session_data *, +int atcommand_skillpool_focus(const int fd, dumb_ptr<map_session_data>, const char *, const char *message) { char character[100]; int skill_; - struct map_session_data *pl_sd; + dumb_ptr<map_session_data> pl_sd; if (!message || !*message || sscanf(message, "%d %99[^\n]", &skill_, character) < 1) @@ -6441,12 +6442,12 @@ int atcommand_skillpool_focus(const int fd, struct map_session_data *, return 0; } -int atcommand_skillpool_unfocus(const int fd, struct map_session_data *, +int atcommand_skillpool_unfocus(const int fd, dumb_ptr<map_session_data>, const char *, const char *message) { char character[100]; int skill_; - struct map_session_data *pl_sd; + dumb_ptr<map_session_data> pl_sd; if (!message || !*message || sscanf(message, "%d %99[^\n]", &skill_, character) < 1) @@ -6470,12 +6471,12 @@ int atcommand_skillpool_unfocus(const int fd, struct map_session_data *, return 0; } -int atcommand_skill_learn(const int fd, struct map_session_data *, +int atcommand_skill_learn(const int fd, dumb_ptr<map_session_data>, const char *, const char *message) { char character[100]; int skill_, level; - struct map_session_data *pl_sd; + dumb_ptr<map_session_data> pl_sd; if (!message || !*message || sscanf(message, "%d %d %99[^\n]", &skill_, &level, character) < 1) @@ -6498,7 +6499,7 @@ int atcommand_skill_learn(const int fd, struct map_session_data *, return 0; } -int atcommand_ipcheck(const int fd, struct map_session_data *, +int atcommand_ipcheck(const int fd, dumb_ptr<map_session_data>, const char *, const char *message) { struct sockaddr_in sai; @@ -6514,8 +6515,8 @@ int atcommand_ipcheck(const int fd, struct map_session_data *, return -1; } - map_session_data *pl_sd; - if ((pl_sd = map_nick2sd(character)) == NULL) + dumb_ptr<map_session_data> pl_sd = map_nick2sd(character); + if (pl_sd == NULL) { clif_displaymessage(fd, "Character not found."); return -1; @@ -6537,7 +6538,7 @@ int atcommand_ipcheck(const int fd, struct map_session_data *, { if (!session[i]) continue; - pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + pl_sd = dumb_ptr<map_session_data>(static_cast<map_session_data *>(session[i]->session_data.get())); if (pl_sd && pl_sd->state.auth) { if (getpeername(pl_sd->fd, (struct sockaddr *)&sai, &sa_len)) @@ -6559,14 +6560,14 @@ int atcommand_ipcheck(const int fd, struct map_session_data *, return 0; } -int atcommand_doomspot(const int fd, struct map_session_data *sd, +int atcommand_doomspot(const int fd, dumb_ptr<map_session_data> sd, const char *, const char *) { for (int i = 0; i < fd_max; i++) { if (!session[i]) continue; - map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + dumb_ptr<map_session_data> pl_sd = dumb_ptr<map_session_data>(static_cast<map_session_data *>(session[i]->session_data.get())); if (pl_sd && pl_sd->state.auth && i != fd && sd->bl_m == pl_sd->bl_m && sd->bl_x == pl_sd->bl_x && sd->bl_y == pl_sd->bl_y diff --git a/src/map/atcommand.hpp b/src/map/atcommand.hpp index a226b76..7033972 100644 --- a/src/map/atcommand.hpp +++ b/src/map/atcommand.hpp @@ -3,12 +3,14 @@ #include "../common/const_array.hpp" -bool is_atcommand(const int fd, struct map_session_data *sd, +#include "map.hpp" + +bool is_atcommand(const int fd, dumb_ptr<map_session_data> sd, const char *message, int gmlvl); int atcommand_config_read(const char *cfgName); -void log_atcommand(struct map_session_data *sd, const_string cmd); +void log_atcommand(dumb_ptr<map_session_data> sd, const_string cmd); // only used by map.cpp extern char *gm_logfile_name; diff --git a/src/map/battle.cpp b/src/map/battle.cpp index 34d4751..8e7b174 100644 --- a/src/map/battle.cpp +++ b/src/map/battle.cpp @@ -25,15 +25,15 @@ struct Battle_Config battle_config; *------------------------------------------ */ static -int battle_counttargeted(struct block_list *bl, struct block_list *src, +int battle_counttargeted(dumb_ptr<block_list> bl, dumb_ptr<block_list> src, ATK target_lv) { nullpo_ret(bl); if (bl->bl_type == BL::PC) - return pc_counttargeted((struct map_session_data *) bl, src, + return pc_counttargeted(bl->as_player(), src, target_lv); else if (bl->bl_type == BL::MOB) - return mob_counttargeted((struct mob_data *) bl, src, target_lv); + return mob_counttargeted(bl->as_mob(), src, target_lv); return 0; } @@ -42,11 +42,11 @@ int battle_counttargeted(struct block_list *bl, struct block_list *src, * 戻りは整数で0以上 *------------------------------------------ */ -int battle_get_class(struct block_list *bl) +int battle_get_class(dumb_ptr<block_list> bl) { nullpo_ret(bl); if (bl->bl_type == BL::MOB) - return ((struct mob_data *) bl)->mob_class; + return bl->as_mob()->mob_class; else if (bl->bl_type == BL::PC) return 0; else @@ -58,13 +58,13 @@ int battle_get_class(struct block_list *bl) * 戻りは整数で0以上 *------------------------------------------ */ -DIR battle_get_dir(struct block_list *bl) +DIR battle_get_dir(dumb_ptr<block_list> bl) { nullpo_retr(DIR::S, bl); if (bl->bl_type == BL::MOB) - return ((struct mob_data *) bl)->dir; + return bl->as_mob()->dir; else if (bl->bl_type == BL::PC) - return ((struct map_session_data *) bl)->dir; + return bl->as_player()->dir; else return DIR::S; } @@ -74,13 +74,13 @@ DIR battle_get_dir(struct block_list *bl) * 戻りは整数で0以上 *------------------------------------------ */ -int battle_get_lv(struct block_list *bl) +int battle_get_lv(dumb_ptr<block_list> bl) { nullpo_ret(bl); if (bl->bl_type == BL::MOB) - return ((struct mob_data *) bl)->stats[mob_stat::LV]; + return bl->as_mob()->stats[mob_stat::LV]; else if (bl->bl_type == BL::PC) - return ((struct map_session_data *) bl)->status.base_level; + return bl->as_player()->status.base_level; else return 0; } @@ -90,13 +90,13 @@ int battle_get_lv(struct block_list *bl) * 戻りは整数で0以上 *------------------------------------------ */ -int battle_get_range(struct block_list *bl) +int battle_get_range(dumb_ptr<block_list> bl) { nullpo_ret(bl); if (bl->bl_type == BL::MOB) - return mob_db[((struct mob_data *) bl)->mob_class].range; + return mob_db[bl->as_mob()->mob_class].range; else if (bl->bl_type == BL::PC) - return ((struct map_session_data *) bl)->attackrange; + return bl->as_player()->attackrange; else return 0; } @@ -106,13 +106,13 @@ int battle_get_range(struct block_list *bl) * 戻りは整数で0以上 *------------------------------------------ */ -int battle_get_hp(struct block_list *bl) +int battle_get_hp(dumb_ptr<block_list> bl) { nullpo_retr(1, bl); if (bl->bl_type == BL::MOB) - return ((struct mob_data *) bl)->hp; + return bl->as_mob()->hp; else if (bl->bl_type == BL::PC) - return ((struct map_session_data *) bl)->status.hp; + return bl->as_player()->status.hp; else return 1; } @@ -122,17 +122,17 @@ int battle_get_hp(struct block_list *bl) * 戻りは整数で0以上 *------------------------------------------ */ -int battle_get_max_hp(struct block_list *bl) +int battle_get_max_hp(dumb_ptr<block_list> bl) { nullpo_retr(1, bl); - if (bl->bl_type == BL::PC && ((struct map_session_data *) bl)) - return ((struct map_session_data *) bl)->status.max_hp; + if (bl->bl_type == BL::PC) + return bl->as_player()->status.max_hp; else { int max_hp = 1; - if (bl->bl_type == BL::MOB && ((struct mob_data *) bl)) + if (bl->bl_type == BL::MOB) { - max_hp = ((struct mob_data *) bl)->stats[mob_stat::MAX_HP]; + max_hp = bl->as_mob()->stats[mob_stat::MAX_HP]; { if (battle_config.monster_hp_rate != 100) max_hp = (max_hp * battle_config.monster_hp_rate) / 100; @@ -149,17 +149,17 @@ int battle_get_max_hp(struct block_list *bl) * 戻りは整数で0以上 *------------------------------------------ */ -int battle_get_str(struct block_list *bl) +int battle_get_str(dumb_ptr<block_list> bl) { int str = 0; eptr<struct status_change, StatusChange> sc_data; nullpo_ret(bl); sc_data = battle_get_sc_data(bl); - if (bl->bl_type == BL::MOB && ((struct mob_data *) bl)) - str = ((struct mob_data *) bl)->stats[mob_stat::STR]; - else if (bl->bl_type == BL::PC && ((struct map_session_data *) bl)) - return ((struct map_session_data *) bl)->paramc[ATTR::STR]; + if (bl->bl_type == BL::MOB) + str = bl->as_mob()->stats[mob_stat::STR]; + else if (bl->bl_type == BL::PC) + return bl->as_player()->paramc[ATTR::STR]; if (str < 0) str = 0; @@ -172,7 +172,7 @@ int battle_get_str(struct block_list *bl) *------------------------------------------ */ -int battle_get_agi(struct block_list *bl) +int battle_get_agi(dumb_ptr<block_list> bl) { int agi = 0; eptr<struct status_change, StatusChange> sc_data; @@ -180,9 +180,9 @@ int battle_get_agi(struct block_list *bl) nullpo_ret(bl); sc_data = battle_get_sc_data(bl); if (bl->bl_type == BL::MOB) - agi = ((struct mob_data *) bl)->stats[mob_stat::AGI]; + agi = bl->as_mob()->stats[mob_stat::AGI]; else if (bl->bl_type == BL::PC) - agi = ((struct map_session_data *) bl)->paramc[ATTR::AGI]; + agi = bl->as_player()->paramc[ATTR::AGI]; if (agi < 0) agi = 0; @@ -194,7 +194,7 @@ int battle_get_agi(struct block_list *bl) * 戻りは整数で0以上 *------------------------------------------ */ -int battle_get_vit(struct block_list *bl) +int battle_get_vit(dumb_ptr<block_list> bl) { int vit = 0; eptr<struct status_change, StatusChange> sc_data; @@ -202,9 +202,9 @@ int battle_get_vit(struct block_list *bl) nullpo_ret(bl); sc_data = battle_get_sc_data(bl); if (bl->bl_type == BL::MOB) - vit = ((struct mob_data *) bl)->stats[mob_stat::VIT]; + vit = bl->as_mob()->stats[mob_stat::VIT]; else if (bl->bl_type == BL::PC) - vit = ((struct map_session_data *) bl)->paramc[ATTR::VIT]; + vit = bl->as_player()->paramc[ATTR::VIT]; if (vit < 0) vit = 0; @@ -216,7 +216,7 @@ int battle_get_vit(struct block_list *bl) * 戻りは整数で0以上 *------------------------------------------ */ -int battle_get_int(struct block_list *bl) +int battle_get_int(dumb_ptr<block_list> bl) { int int_ = 0; eptr<struct status_change, StatusChange> sc_data; @@ -224,9 +224,9 @@ int battle_get_int(struct block_list *bl) nullpo_ret(bl); sc_data = battle_get_sc_data(bl); if (bl->bl_type == BL::MOB) - int_ = ((struct mob_data *) bl)->stats[mob_stat::INT]; + int_ = bl->as_mob()->stats[mob_stat::INT]; else if (bl->bl_type == BL::PC) - int_ = ((struct map_session_data *) bl)->paramc[ATTR::INT]; + int_ = bl->as_player()->paramc[ATTR::INT]; if (int_ < 0) int_ = 0; @@ -238,7 +238,7 @@ int battle_get_int(struct block_list *bl) * 戻りは整数で0以上 *------------------------------------------ */ -int battle_get_dex(struct block_list *bl) +int battle_get_dex(dumb_ptr<block_list> bl) { int dex = 0; eptr<struct status_change, StatusChange> sc_data; @@ -246,9 +246,9 @@ int battle_get_dex(struct block_list *bl) nullpo_ret(bl); sc_data = battle_get_sc_data(bl); if (bl->bl_type == BL::MOB) - dex = ((struct mob_data *) bl)->stats[mob_stat::DEX]; + dex = bl->as_mob()->stats[mob_stat::DEX]; else if (bl->bl_type == BL::PC) - dex = ((struct map_session_data *) bl)->paramc[ATTR::DEX]; + dex = bl->as_player()->paramc[ATTR::DEX]; if (dex < 0) dex = 0; @@ -260,7 +260,7 @@ int battle_get_dex(struct block_list *bl) * 戻りは整数で0以上 *------------------------------------------ */ -int battle_get_luk(struct block_list *bl) +int battle_get_luk(dumb_ptr<block_list> bl) { int luk = 0; eptr<struct status_change, StatusChange> sc_data; @@ -268,9 +268,9 @@ int battle_get_luk(struct block_list *bl) nullpo_ret(bl); sc_data = battle_get_sc_data(bl); if (bl->bl_type == BL::MOB) - luk = ((struct mob_data *) bl)->stats[mob_stat::LUK]; + luk = bl->as_mob()->stats[mob_stat::LUK]; else if (bl->bl_type == BL::PC) - luk = ((struct map_session_data *) bl)->paramc[ATTR::LUK]; + luk = bl->as_player()->paramc[ATTR::LUK]; if (luk < 0) luk = 0; @@ -283,7 +283,7 @@ int battle_get_luk(struct block_list *bl) *------------------------------------------ */ static -int battle_get_flee(struct block_list *bl) +int battle_get_flee(dumb_ptr<block_list> bl) { int flee = 1; eptr<struct status_change, StatusChange> sc_data; @@ -291,7 +291,7 @@ int battle_get_flee(struct block_list *bl) nullpo_retr(1, bl); sc_data = battle_get_sc_data(bl); if (bl->bl_type == BL::PC) - flee = ((struct map_session_data *) bl)->flee; + flee = bl->as_player()->flee; else flee = battle_get_agi(bl) + battle_get_lv(bl); @@ -312,7 +312,7 @@ int battle_get_flee(struct block_list *bl) *------------------------------------------ */ static -int battle_get_hit(struct block_list *bl) +int battle_get_hit(dumb_ptr<block_list> bl) { int hit = 1; eptr<struct status_change, StatusChange> sc_data; @@ -320,7 +320,7 @@ int battle_get_hit(struct block_list *bl) nullpo_retr(1, bl); sc_data = battle_get_sc_data(bl); if (bl->bl_type == BL::PC) - hit = ((struct map_session_data *) bl)->hit; + hit = bl->as_player()->hit; else hit = battle_get_dex(bl) + battle_get_lv(bl); @@ -340,7 +340,7 @@ int battle_get_hit(struct block_list *bl) *------------------------------------------ */ static -int battle_get_flee2(struct block_list *bl) +int battle_get_flee2(dumb_ptr<block_list> bl) { int flee2 = 1; eptr<struct status_change, StatusChange> sc_data; @@ -349,10 +349,9 @@ int battle_get_flee2(struct block_list *bl) sc_data = battle_get_sc_data(bl); if (bl->bl_type == BL::PC) { + dumb_ptr<map_session_data> sd = bl->as_player(); flee2 = battle_get_luk(bl) + 10; - flee2 += - ((struct map_session_data *) bl)->flee2 - - (((struct map_session_data *) bl)->paramc[ATTR::LUK] + 10); + flee2 += sd->flee2 - (sd->paramc[ATTR::LUK] + 10); } else flee2 = battle_get_luk(bl) + 1; @@ -373,7 +372,7 @@ int battle_get_flee2(struct block_list *bl) *------------------------------------------ */ static -int battle_get_critical(struct block_list *bl) +int battle_get_critical(dumb_ptr<block_list> bl) { int critical = 1; eptr<struct status_change, StatusChange> sc_data; @@ -382,10 +381,9 @@ int battle_get_critical(struct block_list *bl) sc_data = battle_get_sc_data(bl); if (bl->bl_type == BL::PC) { + dumb_ptr<map_session_data> sd = bl->as_player(); critical = battle_get_luk(bl) * 2 + 10; - critical += - ((struct map_session_data *) bl)->critical - - ((((struct map_session_data *) bl)->paramc[ATTR::LUK] * 3) + 10); + critical += sd->critical - ((sd->paramc[ATTR::LUK] * 3) + 10); } else critical = battle_get_luk(bl) * 3 + 1; @@ -401,7 +399,7 @@ int battle_get_critical(struct block_list *bl) *------------------------------------------ */ static -int battle_get_baseatk(struct block_list *bl) +int battle_get_baseatk(dumb_ptr<block_list> bl) { eptr<struct status_change, StatusChange> sc_data; int batk = 1; @@ -409,7 +407,7 @@ int battle_get_baseatk(struct block_list *bl) nullpo_retr(1, bl); sc_data = battle_get_sc_data(bl); if (bl->bl_type == BL::PC) - batk = ((struct map_session_data *) bl)->base_atk; //設定されているbase_atk + batk = bl->as_player()->base_atk; //設定されているbase_atk else { //それ以外なら int str, dstr; @@ -428,7 +426,7 @@ int battle_get_baseatk(struct block_list *bl) *------------------------------------------ */ static -int battle_get_atk(struct block_list *bl) +int battle_get_atk(dumb_ptr<block_list> bl) { eptr<struct status_change, StatusChange> sc_data; int atk = 0; @@ -436,9 +434,9 @@ int battle_get_atk(struct block_list *bl) nullpo_ret(bl); sc_data = battle_get_sc_data(bl); if (bl->bl_type == BL::PC) - atk = ((struct map_session_data *) bl)->watk; + atk = bl->as_player()->watk; else if (bl->bl_type == BL::MOB) - atk = ((struct mob_data *) bl)->stats[mob_stat::ATK1]; + atk = bl->as_mob()->stats[mob_stat::ATK1]; if (atk < 0) atk = 0; @@ -451,11 +449,11 @@ int battle_get_atk(struct block_list *bl) *------------------------------------------ */ static -int battle_get_atk_(struct block_list *bl) +int battle_get_atk_(dumb_ptr<block_list> bl) { nullpo_ret(bl); if (bl->bl_type == BL::PC) - return ((struct map_session_data *) bl)->watk_; + return bl->as_player()->watk_; else return 0; } @@ -466,16 +464,16 @@ int battle_get_atk_(struct block_list *bl) *------------------------------------------ */ static -int battle_get_atk2(struct block_list *bl) +int battle_get_atk2(dumb_ptr<block_list> bl) { nullpo_ret(bl); if (bl->bl_type == BL::PC) - return ((struct map_session_data *) bl)->watk2; + return bl->as_player()->watk2; else { int atk2 = 0; if (bl->bl_type == BL::MOB) - atk2 = ((struct mob_data *) bl)->stats[mob_stat::ATK2]; + atk2 = bl->as_mob()->stats[mob_stat::ATK2]; if (atk2 < 0) atk2 = 0; @@ -489,11 +487,11 @@ int battle_get_atk2(struct block_list *bl) *------------------------------------------ */ static -int battle_get_atk_2(struct block_list *bl) +int battle_get_atk_2(dumb_ptr<block_list> bl) { nullpo_ret(bl); if (bl->bl_type == BL::PC) - return ((struct map_session_data *) bl)->watk_2; + return bl->as_player()->watk_2; else return 0; } @@ -504,7 +502,7 @@ int battle_get_atk_2(struct block_list *bl) *------------------------------------------ */ static -int battle_get_matk1(struct block_list *bl) +int battle_get_matk1(dumb_ptr<block_list> bl) { eptr<struct status_change, StatusChange> sc_data; nullpo_ret(bl); @@ -517,7 +515,7 @@ int battle_get_matk1(struct block_list *bl) return matk; } else if (bl->bl_type == BL::PC) - return ((struct map_session_data *) bl)->matk1; + return bl->as_player()->matk1; else return 0; } @@ -528,7 +526,7 @@ int battle_get_matk1(struct block_list *bl) *------------------------------------------ */ static -int battle_get_matk2(struct block_list *bl) +int battle_get_matk2(dumb_ptr<block_list> bl) { nullpo_ret(bl); if (bl->bl_type == BL::MOB) @@ -539,7 +537,7 @@ int battle_get_matk2(struct block_list *bl) return matk; } else if (bl->bl_type == BL::PC) - return ((struct map_session_data *) bl)->matk2; + return bl->as_player()->matk2; else return 0; } @@ -549,7 +547,7 @@ int battle_get_matk2(struct block_list *bl) * 戻りは整数で0以上 *------------------------------------------ */ -int battle_get_def(struct block_list *bl) +int battle_get_def(dumb_ptr<block_list> bl) { eptr<struct status_change, StatusChange> sc_data; int def = 0; @@ -558,11 +556,11 @@ int battle_get_def(struct block_list *bl) sc_data = battle_get_sc_data(bl); if (bl->bl_type == BL::PC) { - def = ((struct map_session_data *) bl)->def; + def = bl->as_player()->def; } else if (bl->bl_type == BL::MOB) { - def = ((struct mob_data *) bl)->stats[mob_stat::DEF]; + def = bl->as_mob()->stats[mob_stat::DEF]; } if (def < 1000000) @@ -585,7 +583,7 @@ int battle_get_def(struct block_list *bl) * 戻りは整数で0以上 *------------------------------------------ */ -int battle_get_mdef(struct block_list *bl) +int battle_get_mdef(dumb_ptr<block_list> bl) { eptr<struct status_change, StatusChange> sc_data; int mdef = 0; @@ -593,9 +591,9 @@ int battle_get_mdef(struct block_list *bl) nullpo_ret(bl); sc_data = battle_get_sc_data(bl); if (bl->bl_type == BL::PC) - mdef = ((struct map_session_data *) bl)->mdef; + mdef = bl->as_player()->mdef; else if (bl->bl_type == BL::MOB) - mdef = ((struct mob_data *) bl)->stats[mob_stat::MDEF]; + mdef = bl->as_mob()->stats[mob_stat::MDEF]; if (mdef < 1000000) { @@ -620,7 +618,7 @@ int battle_get_mdef(struct block_list *bl) * 戻りは整数で1以上 *------------------------------------------ */ -int battle_get_def2(struct block_list *bl) +int battle_get_def2(dumb_ptr<block_list> bl) { eptr<struct status_change, StatusChange> sc_data; int def2 = 1; @@ -628,9 +626,9 @@ int battle_get_def2(struct block_list *bl) nullpo_retr(1, bl); sc_data = battle_get_sc_data(bl); if (bl->bl_type == BL::PC) - def2 = ((struct map_session_data *) bl)->def2; + def2 = bl->as_player()->def2; else if (bl->bl_type == BL::MOB) - def2 = ((struct mob_data *) bl)->stats[mob_stat::VIT]; + def2 = bl->as_mob()->stats[mob_stat::VIT]; if (sc_data) { @@ -648,19 +646,21 @@ int battle_get_def2(struct block_list *bl) * 戻りは整数で0以上 *------------------------------------------ */ -int battle_get_mdef2(struct block_list *bl) +int battle_get_mdef2(dumb_ptr<block_list> bl) { int mdef2 = 0; nullpo_ret(bl); if (bl->bl_type == BL::MOB) - mdef2 = - ((struct mob_data *) bl)->stats[mob_stat::INT] + - (((struct mob_data *) bl)->stats[mob_stat::VIT] >> 1); + { + dumb_ptr<mob_data> md = bl->as_mob(); + mdef2 = md->stats[mob_stat::INT] + (md->stats[mob_stat::VIT] >> 1); + } else if (bl->bl_type == BL::PC) - mdef2 = - ((struct map_session_data *) bl)->mdef2 + - (((struct map_session_data *) bl)->paramc[ATTR::VIT] >> 1); + { + dumb_ptr<map_session_data> sd = bl->as_player(); + mdef2 = sd->mdef2 + (sd->paramc[ATTR::VIT] >> 1); + } if (mdef2 < 0) mdef2 = 0; @@ -673,16 +673,16 @@ int battle_get_mdef2(struct block_list *bl) * Speedは小さいほうが移動速度が速い *------------------------------------------ */ -interval_t battle_get_speed(struct block_list *bl) +interval_t battle_get_speed(dumb_ptr<block_list> bl) { nullpo_retr(std::chrono::seconds(1), bl); if (bl->bl_type == BL::PC) - return ((struct map_session_data *) bl)->speed; + return bl->as_player()->speed; else { interval_t speed = std::chrono::seconds(1); if (bl->bl_type == BL::MOB) - speed = static_cast<interval_t>(((struct mob_data *) bl)->stats[mob_stat::SPEED]); + speed = static_cast<interval_t>(bl->as_mob()->stats[mob_stat::SPEED]); return std::max(speed, std::chrono::milliseconds(1)); } @@ -694,18 +694,18 @@ interval_t battle_get_speed(struct block_list *bl) *------------------------------------------ */ // TODO figure out what all the doubling is about -interval_t battle_get_adelay(struct block_list *bl) +interval_t battle_get_adelay(dumb_ptr<block_list> bl) { nullpo_retr(std::chrono::seconds(4), bl); if (bl->bl_type == BL::PC) - return ((struct map_session_data *) bl)->aspd * 2; + return bl->as_player()->aspd * 2; else { eptr<struct status_change, StatusChange> sc_data = battle_get_sc_data(bl); interval_t adelay = std::chrono::seconds(4); int aspd_rate = 100; if (bl->bl_type == BL::MOB) - adelay = static_cast<interval_t>(((struct mob_data *) bl)->stats[mob_stat::ADELAY]); + adelay = static_cast<interval_t>(bl->as_mob()->stats[mob_stat::ADELAY]); if (sc_data) { @@ -722,18 +722,18 @@ interval_t battle_get_adelay(struct block_list *bl) } } -interval_t battle_get_amotion(struct block_list *bl) +interval_t battle_get_amotion(dumb_ptr<block_list> bl) { nullpo_retr(std::chrono::seconds(2), bl); if (bl->bl_type == BL::PC) - return ((struct map_session_data *) bl)->amotion; + return bl->as_player()->amotion; else { eptr<struct status_change, StatusChange> sc_data = battle_get_sc_data(bl); interval_t amotion = std::chrono::seconds(2); int aspd_rate = 100; if (bl->bl_type == BL::MOB) - amotion = static_cast<interval_t>(mob_db[((struct mob_data *) bl)->mob_class].amotion); + amotion = static_cast<interval_t>(mob_db[bl->as_mob()->mob_class].amotion); if (sc_data) { @@ -749,40 +749,40 @@ interval_t battle_get_amotion(struct block_list *bl) } } -interval_t battle_get_dmotion(struct block_list *bl) +interval_t battle_get_dmotion(dumb_ptr<block_list> bl) { nullpo_retr(interval_t::zero(), bl); if (bl->bl_type == BL::MOB) { - return static_cast<interval_t>(mob_db[((struct mob_data *) bl)->mob_class].dmotion); + return static_cast<interval_t>(mob_db[bl->as_mob()->mob_class].dmotion); } else if (bl->bl_type == BL::PC) { - return ((struct map_session_data *) bl)->dmotion; + return bl->as_player()->dmotion; } else return std::chrono::seconds(2); } -LevelElement battle_get_element(struct block_list *bl) +LevelElement battle_get_element(dumb_ptr<block_list> bl) { LevelElement ret = {2, Element::neutral}; nullpo_retr(ret, bl); if (bl->bl_type == BL::MOB) // 10の位=Lv*2、1の位=属性 - ret = ((struct mob_data *) bl)->def_ele; + ret = bl->as_mob()->def_ele; return ret; } -int battle_get_party_id(struct block_list *bl) +int battle_get_party_id(dumb_ptr<block_list> bl) { nullpo_ret(bl); if (bl->bl_type == BL::PC) - return ((struct map_session_data *) bl)->status.party_id; + return bl->as_player()->status.party_id; else if (bl->bl_type == BL::MOB) { - struct mob_data *md = (struct mob_data *) bl; + dumb_ptr<mob_data> md = bl->as_mob(); if (md->master_id > 0) return -md->master_id; return -md->bl_id; @@ -790,27 +790,27 @@ int battle_get_party_id(struct block_list *bl) return 0; } -Race battle_get_race(struct block_list *bl) +Race battle_get_race(dumb_ptr<block_list> bl) { nullpo_retr(Race::formless, bl); if (bl->bl_type == BL::MOB) - return mob_db[((struct mob_data *) bl)->mob_class].race; + return mob_db[bl->as_mob()->mob_class].race; else if (bl->bl_type == BL::PC) return Race::demihuman; else return Race::formless; } -MobMode battle_get_mode(struct block_list *bl) +MobMode battle_get_mode(dumb_ptr<block_list> bl) { nullpo_retr(MobMode::CAN_MOVE, bl); if (bl->bl_type == BL::MOB) - return mob_db[((struct mob_data *) bl)->mob_class].mode; + return mob_db[bl->as_mob()->mob_class].mode; // とりあえず動くということで1 return MobMode::CAN_MOVE; } -int battle_get_stat(SP stat_id, struct block_list *bl) +int battle_get_stat(SP stat_id, dumb_ptr<block_list> bl) { switch (stat_id) { @@ -832,75 +832,75 @@ int battle_get_stat(SP stat_id, struct block_list *bl) } // StatusChange系の所得 -eptr<struct status_change, StatusChange> battle_get_sc_data(struct block_list *bl) +eptr<struct status_change, StatusChange> battle_get_sc_data(dumb_ptr<block_list> bl) { nullpo_retr(nullptr, bl); switch (bl->bl_type) { case BL::MOB: - return ((struct mob_data *)(bl))->sc_data; + return bl->as_mob()->sc_data; case BL::PC: - return ((struct map_session_data *)(bl))->sc_data; + return bl->as_player()->sc_data; } return nullptr; } -short *battle_get_sc_count(struct block_list *bl) +short *battle_get_sc_count(dumb_ptr<block_list> bl) { nullpo_retr(NULL, bl); if (bl->bl_type == BL::MOB) - return &((struct mob_data *) bl)->sc_count; + return &bl->as_mob()->sc_count; else if (bl->bl_type == BL::PC) - return &((struct map_session_data *) bl)->sc_count; + return &bl->as_player()->sc_count; return NULL; } -Opt1 *battle_get_opt1(struct block_list *bl) +Opt1 *battle_get_opt1(dumb_ptr<block_list> bl) { nullpo_ret(bl); if (bl->bl_type == BL::MOB) - return &((struct mob_data *) bl)->opt1; + return &bl->as_mob()->opt1; else if (bl->bl_type == BL::PC) - return &((struct map_session_data *) bl)->opt1; - else if (bl->bl_type == BL::NPC && (struct npc_data *) bl) - return &((struct npc_data *) bl)->opt1; + return &bl->as_player()->opt1; + else if (bl->bl_type == BL::NPC) + return &bl->as_npc()->opt1; return 0; } -Opt2 *battle_get_opt2(struct block_list *bl) +Opt2 *battle_get_opt2(dumb_ptr<block_list> bl) { nullpo_ret(bl); if (bl->bl_type == BL::MOB) - return &((struct mob_data *) bl)->opt2; + return &bl->as_mob()->opt2; else if (bl->bl_type == BL::PC) - return &((struct map_session_data *) bl)->opt2; - else if (bl->bl_type == BL::NPC && (struct npc_data *) bl) - return &((struct npc_data *) bl)->opt2; + return &bl->as_player()->opt2; + else if (bl->bl_type == BL::NPC) + return &bl->as_npc()->opt2; return 0; } -Opt3 *battle_get_opt3(struct block_list *bl) +Opt3 *battle_get_opt3(dumb_ptr<block_list> bl) { nullpo_ret(bl); if (bl->bl_type == BL::MOB) - return &((struct mob_data *) bl)->opt3; + return &bl->as_mob()->opt3; else if (bl->bl_type == BL::PC) - return &((struct map_session_data *) bl)->opt3; - else if (bl->bl_type == BL::NPC && (struct npc_data *) bl) - return &((struct npc_data *) bl)->opt3; + return &bl->as_player()->opt3; + else if (bl->bl_type == BL::NPC) + return &bl->as_npc()->opt3; return 0; } -Option *battle_get_option(struct block_list *bl) +Option *battle_get_option(dumb_ptr<block_list> bl) { nullpo_ret(bl); if (bl->bl_type == BL::MOB) - return &((struct mob_data *) bl)->option; + return &bl->as_mob()->option; else if (bl->bl_type == BL::PC) - return &((struct map_session_data *) bl)->status.option; - else if (bl->bl_type == BL::NPC && (struct npc_data *) bl) - return &((struct npc_data *) bl)->option; + return &bl->as_player()->status.option; + else if (bl->bl_type == BL::NPC) + return &bl->as_npc()->option; return 0; } @@ -909,13 +909,13 @@ Option *battle_get_option(struct block_list *bl) // ダメージの遅延 struct battle_delay_damage_ { - struct block_list *src, *target; + dumb_ptr<block_list> src, *target; int damage; int flag; }; // 実際にHPを操作 -int battle_damage(struct block_list *bl, struct block_list *target, +int battle_damage(dumb_ptr<block_list> bl, dumb_ptr<block_list> target, int damage, int flag) { nullpo_ret(target); //blはNULLで呼ばれることがあるので他でチェック @@ -937,7 +937,7 @@ int battle_damage(struct block_list *bl, struct block_list *target, if (target->bl_type == BL::MOB) { // MOB - struct mob_data *md = (struct mob_data *) target; + dumb_ptr<mob_data> md = target->as_mob(); if (md && md->skilltimer && md->state.skillcastcancel) // 詠唱妨害 skill_castcancel(target, 0); return mob_damage(bl, md, damage, 0); @@ -945,7 +945,7 @@ int battle_damage(struct block_list *bl, struct block_list *target, else if (target->bl_type == BL::PC) { // PC - struct map_session_data *tsd = (struct map_session_data *) target; + dumb_ptr<map_session_data> tsd = target->as_player(); return pc_damage(bl, tsd, damage); @@ -953,13 +953,13 @@ int battle_damage(struct block_list *bl, struct block_list *target, return 0; } -int battle_heal(struct block_list *bl, struct block_list *target, int hp, +int battle_heal(dumb_ptr<block_list> bl, dumb_ptr<block_list> target, int hp, int sp, int flag) { nullpo_ret(target); //blはNULLで呼ばれることがあるので他でチェック if (target->bl_type == BL::PC - && pc_isdead((struct map_session_data *) target)) + && pc_isdead(target->as_player())) return 0; if (hp == 0 && sp == 0) return 0; @@ -968,31 +968,31 @@ int battle_heal(struct block_list *bl, struct block_list *target, int hp, return battle_damage(bl, target, -hp, flag); if (target->bl_type == BL::MOB) - return mob_heal((struct mob_data *) target, hp); + return mob_heal(target->as_mob(), hp); else if (target->bl_type == BL::PC) - return pc_heal((struct map_session_data *) target, hp, sp); + return pc_heal(target->as_player(), hp, sp); return 0; } // 攻撃停止 -int battle_stopattack(struct block_list *bl) +int battle_stopattack(dumb_ptr<block_list> bl) { nullpo_ret(bl); if (bl->bl_type == BL::MOB) - return mob_stopattack((struct mob_data *) bl); + return mob_stopattack(bl->as_mob()); else if (bl->bl_type == BL::PC) - return pc_stopattack((struct map_session_data *) bl); + return pc_stopattack(bl->as_player()); return 0; } // 移動停止 -int battle_stopwalking(struct block_list *bl, int type) +int battle_stopwalking(dumb_ptr<block_list> bl, int type) { nullpo_ret(bl); if (bl->bl_type == BL::MOB) - return mob_stop_walking((struct mob_data *) bl, type); + return mob_stop_walking(bl->as_mob(), type); else if (bl->bl_type == BL::PC) - return pc_stop_walking((struct map_session_data *) bl, type); + return pc_stop_walking(bl->as_player(), type); return 0; } @@ -1001,16 +1001,16 @@ int battle_stopwalking(struct block_list *bl, int type) *------------------------------------------ */ static -int battle_calc_damage(struct block_list *, struct block_list *bl, +int battle_calc_damage(dumb_ptr<block_list>, dumb_ptr<block_list> bl, int damage, int div_, SkillID, int, BF flag) { - struct mob_data *md = NULL; + dumb_ptr<mob_data> md = NULL; nullpo_ret(bl); if (bl->bl_type == BL::MOB) - md = (struct mob_data *) bl; + md = bl->as_mob(); if (battle_config.skill_min_damage || bool(flag & BF::MISC)) @@ -1031,13 +1031,13 @@ int battle_calc_damage(struct block_list *, struct block_list *bl, } static -struct Damage battle_calc_mob_weapon_attack(struct block_list *src, - struct block_list *target, +struct Damage battle_calc_mob_weapon_attack(dumb_ptr<block_list> src, + dumb_ptr<block_list> target, SkillID skill_num, int skill_lv, int) { - struct map_session_data *tsd = NULL; - struct mob_data *md = (struct mob_data *) src, *tmd = NULL; + dumb_ptr<map_session_data> tsd = NULL; + dumb_ptr<mob_data> md = src->as_mob(), tmd = NULL; int hitrate, flee, cri = 0, atkmin, atkmax; int target_count = 1; int def1 = battle_get_def(target); @@ -1060,9 +1060,9 @@ struct Damage battle_calc_mob_weapon_attack(struct block_list *src, // ターゲット if (target->bl_type == BL::PC) - tsd = (struct map_session_data *) target; + tsd = target->as_player(); else if (target->bl_type == BL::MOB) - tmd = (struct mob_data *) target; + tmd = target->as_mob(); MobMode t_mode = battle_get_mode(target); t_sc_data = battle_get_sc_data(target); @@ -1284,13 +1284,13 @@ struct Damage battle_calc_mob_weapon_attack(struct block_list *src, return wd; } -int battle_is_unarmed(struct block_list *bl) +int battle_is_unarmed(dumb_ptr<block_list> bl) { if (!bl) return 0; if (bl->bl_type == BL::PC) { - struct map_session_data *sd = (struct map_session_data *) bl; + dumb_ptr<map_session_data> sd = bl->as_player(); return (sd->equip_index[EQUIP::SHIELD] == -1 && sd->equip_index[EQUIP::WEAPON] == -1); @@ -1305,14 +1305,13 @@ int battle_is_unarmed(struct block_list *bl) *------------------------------------------------------------------------- */ static -struct Damage battle_calc_pc_weapon_attack(struct block_list *src, - struct block_list *target, +struct Damage battle_calc_pc_weapon_attack(dumb_ptr<block_list> src, + dumb_ptr<block_list> target, SkillID skill_num, int skill_lv, int) { - struct map_session_data *sd = (struct map_session_data *) src, *tsd = - NULL; - struct mob_data *tmd = NULL; + dumb_ptr<map_session_data> sd = src->as_player(), tsd = NULL; + dumb_ptr<mob_data> tmd = NULL; int hitrate, flee, cri = 0, atkmin, atkmax; int dex, target_count = 1; int def1 = battle_get_def(target); @@ -1342,9 +1341,9 @@ struct Damage battle_calc_pc_weapon_attack(struct block_list *src, // ターゲット if (target->bl_type == BL::PC) //対象がPCなら - tsd = (struct map_session_data *) target; //tsdに代入(tmdはNULL) + tsd = target->as_player(); //tsdに代入(tmdはNULL) else if (target->bl_type == BL::MOB) //対象がMobなら - tmd = (struct mob_data *) target; //tmdに代入(tsdはNULL) + tmd = target->as_mob(); //tmdに代入(tsdはNULL) MobMode t_mode = battle_get_mode(target); //対象のMode t_sc_data = battle_get_sc_data(target); //対象のステータス異常 @@ -1753,8 +1752,8 @@ struct Damage battle_calc_pc_weapon_attack(struct block_list *src, *------------------------------------------ */ static -struct Damage battle_calc_weapon_attack(struct block_list *src, - struct block_list *target, +struct Damage battle_calc_weapon_attack(dumb_ptr<block_list> src, + dumb_ptr<block_list> target, SkillID skill_num, int skill_lv, int wflag) { @@ -1776,8 +1775,8 @@ struct Damage battle_calc_weapon_attack(struct block_list *src, *------------------------------------------ */ static -struct Damage battle_calc_magic_attack(struct block_list *bl, - struct block_list *target, +struct Damage battle_calc_magic_attack(dumb_ptr<block_list> bl, + dumb_ptr<block_list> target, SkillID skill_num, int skill_lv, int) { int mdef1 = battle_get_mdef(target); @@ -1785,7 +1784,7 @@ struct Damage battle_calc_magic_attack(struct block_list *bl, int matk1, matk2, damage = 0, div_ = 1; struct Damage md {}; int normalmagic_flag = 1; - struct map_session_data *sd = NULL; + dumb_ptr<map_session_data> sd = NULL; nullpo_retr(md, bl); nullpo_retr(md, target); @@ -1794,8 +1793,9 @@ struct Damage battle_calc_magic_attack(struct block_list *bl, matk2 = battle_get_matk2(bl); MobMode t_mode = battle_get_mode(target); - if (bl->bl_type == BL::PC && (sd = (struct map_session_data *) bl)) + if (bl->bl_type == BL::PC) { + sd = bl->as_player(); sd->state.attack_type = BF::MAGIC; if (sd->matk_rate != 100) { @@ -1856,11 +1856,11 @@ struct Damage battle_calc_magic_attack(struct block_list *bl, *------------------------------------------ */ static -struct Damage battle_calc_misc_attack(struct block_list *bl, - struct block_list *target, +struct Damage battle_calc_misc_attack(dumb_ptr<block_list> bl, + dumb_ptr<block_list> target, SkillID skill_num, int skill_lv, int) { - struct map_session_data *sd = NULL; + dumb_ptr<map_session_data> sd = NULL; int damage = 0, div_ = 1; struct Damage md {}; int damagefix = 1; @@ -1870,8 +1870,9 @@ struct Damage battle_calc_misc_attack(struct block_list *bl, nullpo_retr(md, bl); nullpo_retr(md, target); - if (bl->bl_type == BL::PC && (sd = (struct map_session_data *) bl)) + if (bl->bl_type == BL::PC) { + sd = bl->as_player(); sd->state.attack_type = BF::MISC; sd->state.arrow_atk = 0; } @@ -1920,8 +1921,8 @@ struct Damage battle_calc_misc_attack(struct block_list *bl, *------------------------------------------ */ struct Damage battle_calc_attack(BF attack_type, - struct block_list *bl, - struct block_list *target, SkillID skill_num, + dumb_ptr<block_list> bl, + dumb_ptr<block_list> target, SkillID skill_num, int skill_lv, int flag) { struct Damage d; @@ -1951,10 +1952,10 @@ struct Damage battle_calc_attack(BF attack_type, * 通常攻撃処理まとめ *------------------------------------------ */ -ATK battle_weapon_attack(struct block_list *src, struct block_list *target, +ATK battle_weapon_attack(dumb_ptr<block_list> src, dumb_ptr<block_list> target, tick_t tick) { - struct map_session_data *sd = NULL; + dumb_ptr<map_session_data> sd = NULL; eptr<struct status_change, StatusChange> t_sc_data = battle_get_sc_data(target); struct Damage wd; @@ -1962,14 +1963,14 @@ ATK battle_weapon_attack(struct block_list *src, struct block_list *target, nullpo_retr(ATK::ZERO, target); if (src->bl_type == BL::PC) - sd = (struct map_session_data *) src; + sd = src->as_player(); if (src->bl_prev == NULL || target->bl_prev == NULL) return ATK::ZERO; if (src->bl_type == BL::PC && pc_isdead(sd)) return ATK::ZERO; if (target->bl_type == BL::PC - && pc_isdead((struct map_session_data *) target)) + && pc_isdead(target->as_player())) return ATK::ZERO; Opt1 *opt1 = battle_get_opt1(src); @@ -2013,7 +2014,7 @@ ATK battle_weapon_attack(struct block_list *src, struct block_list *target, reduction = wd.damage; wd.damage -= reduction; - MAP_LOG_PC(((struct map_session_data *) target), + MAP_LOG_PC(target->as_player(), "MAGIC-ABSORB-DMG %d", reduction); } @@ -2041,21 +2042,21 @@ ATK battle_weapon_attack(struct block_list *src, struct block_list *target, MAP_LOG("PC%d %d:%d,%d WPNDMG %s%d %d FOR %d WPN %d", sd->status.char_id, src->bl_m, src->bl_x, src->bl_y, (target->bl_type == BL::PC) ? "PC" : "MOB", - (target->bl_type == - BL::PC) ? ((struct map_session_data *) target)-> - status.char_id : target->bl_id, + (target->bl_type == BL::PC) + ? target->as_player()-> status.char_id + : target->bl_id, battle_get_class(target), wd.damage + wd.damage2, weapon); } if (target->bl_type == BL::PC) { - struct map_session_data *sd2 = (struct map_session_data *) target; + dumb_ptr<map_session_data> sd2 = target->as_player(); MAP_LOG("PC%d %d:%d,%d WPNINJURY %s%d %d FOR %d", sd2->status.char_id, target->bl_m, target->bl_x, target->bl_y, (src->bl_type == BL::PC) ? "PC" : "MOB", (src->bl_type == BL::PC) - ? ((struct map_session_data *) src)->status.char_id + ? src->as_player()->status.char_id : src->bl_id, battle_get_class(src), wd.damage + wd.damage2); @@ -2065,7 +2066,7 @@ ATK battle_weapon_attack(struct block_list *src, struct block_list *target, if (target->bl_prev != NULL && (target->bl_type != BL::PC || (target->bl_type == BL::PC - && !pc_isdead((struct map_session_data *) target)))) + && !pc_isdead(target->as_player())))) { if (wd.damage > 0 || wd.damage2 > 0) { @@ -2132,11 +2133,11 @@ bool battle_check_undead(Race race, Element element) * = 0x50000:パーティーじゃないか判定(ret:1=パーティでない) *------------------------------------------ */ -int battle_check_target(struct block_list *src, struct block_list *target, +int battle_check_target(dumb_ptr<block_list> src, dumb_ptr<block_list> target, BCT flag) { int s_p, t_p; - struct block_list *ss = src; + dumb_ptr<block_list> ss = src; nullpo_ret(src); nullpo_ret(target); @@ -2158,13 +2159,13 @@ int battle_check_target(struct block_list *src, struct block_list *target, } if (target->bl_type == BL::PC - && ((struct map_session_data *) target)->invincible_timer) + && target->as_player()->invincible_timer) return -1; // Mobでmaster_idがあってspecial_mob_aiなら、召喚主を求める if (src->bl_type == BL::MOB) { - struct mob_data *md = (struct mob_data *) src; + dumb_ptr<mob_data> md = src->as_mob(); if (md && md->master_id > 0) { if (md->master_id == target->bl_id) // 主なら肯定 @@ -2173,7 +2174,7 @@ int battle_check_target(struct block_list *src, struct block_list *target, { if (target->bl_type == BL::MOB) { //special_mob_aiで対象がMob - struct mob_data *tmd = (struct mob_data *) target; + dumb_ptr<mob_data> tmd = target->as_mob(); if (tmd) { if (tmd->master_id != md->master_id) //召喚主が一緒でなければ否定 @@ -2197,11 +2198,11 @@ int battle_check_target(struct block_list *src, struct block_list *target, return 1; if (target->bl_type == BL::PC - && pc_isinvisible((struct map_session_data *) target)) + && pc_isinvisible(target->as_player())) return -1; if (src->bl_prev == NULL || // 死んでるならエラー - (src->bl_type == BL::PC && pc_isdead((struct map_session_data *) src))) + (src->bl_type == BL::PC && pc_isdead(src->as_player()))) return -1; if ((ss->bl_type == BL::PC && target->bl_type == BL::MOB) || @@ -2226,8 +2227,7 @@ int battle_check_target(struct block_list *src, struct block_list *target, if (ss->bl_type == BL::PC && target->bl_type == BL::PC) { // 両方PVPモードなら否定(敵) if (map[ss->bl_m].flag.pvp - || pc_iskiller((struct map_session_data *) ss, - (struct map_session_data *) target)) + || pc_iskiller(ss->as_player(), target->as_player())) { // [MouseJstr] if (battle_config.pk_mode) return 1; // prevent novice engagement in pk_mode [Valaris] @@ -2245,7 +2245,7 @@ int battle_check_target(struct block_list *src, struct block_list *target, * 射程判定 *------------------------------------------ */ -int battle_check_range(struct block_list *src, struct block_list *bl, +int battle_check_range(dumb_ptr<block_list> src, dumb_ptr<block_list> bl, int range) { diff --git a/src/map/battle.hpp b/src/map/battle.hpp index 6d9d8dd..8b7c1bd 100644 --- a/src/map/battle.hpp +++ b/src/map/battle.hpp @@ -27,66 +27,66 @@ struct block_list; // ダメージ計算 struct Damage battle_calc_attack(BF attack_type, - struct block_list *bl, struct block_list *target, + dumb_ptr<block_list> bl, dumb_ptr<block_list> target, SkillID skill_num, int skill_lv, int flag); // 実際にHPを増減 -int battle_damage(struct block_list *bl, struct block_list *target, +int battle_damage(dumb_ptr<block_list> bl, dumb_ptr<block_list> target, int damage, int flag); -int battle_heal(struct block_list *bl, struct block_list *target, int hp, +int battle_heal(dumb_ptr<block_list> bl, dumb_ptr<block_list> target, int hp, int sp, int flag); // 攻撃や移動を止める -int battle_stopattack(struct block_list *bl); -int battle_stopwalking(struct block_list *bl, int type); +int battle_stopattack(dumb_ptr<block_list> bl); +int battle_stopwalking(dumb_ptr<block_list> bl, int type); // 通常攻撃処理まとめ -ATK battle_weapon_attack(struct block_list *bl, struct block_list *target, +ATK battle_weapon_attack(dumb_ptr<block_list> bl, dumb_ptr<block_list> target, tick_t tick); -int battle_is_unarmed(struct block_list *bl); -int battle_get_class(struct block_list *bl); -DIR battle_get_dir(struct block_list *bl); -int battle_get_lv(struct block_list *bl); -int battle_get_range(struct block_list *bl); -int battle_get_hp(struct block_list *bl); -int battle_get_max_hp(struct block_list *bl); -int battle_get_str(struct block_list *bl); -int battle_get_agi(struct block_list *bl); -int battle_get_vit(struct block_list *bl); -int battle_get_int(struct block_list *bl); -int battle_get_dex(struct block_list *bl); -int battle_get_luk(struct block_list *bl); -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); -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); +int battle_is_unarmed(dumb_ptr<block_list> bl); +int battle_get_class(dumb_ptr<block_list> bl); +DIR battle_get_dir(dumb_ptr<block_list> bl); +int battle_get_lv(dumb_ptr<block_list> bl); +int battle_get_range(dumb_ptr<block_list> bl); +int battle_get_hp(dumb_ptr<block_list> bl); +int battle_get_max_hp(dumb_ptr<block_list> bl); +int battle_get_str(dumb_ptr<block_list> bl); +int battle_get_agi(dumb_ptr<block_list> bl); +int battle_get_vit(dumb_ptr<block_list> bl); +int battle_get_int(dumb_ptr<block_list> bl); +int battle_get_dex(dumb_ptr<block_list> bl); +int battle_get_luk(dumb_ptr<block_list> bl); +int battle_get_def(dumb_ptr<block_list> bl); +int battle_get_mdef(dumb_ptr<block_list> bl); +int battle_get_def2(dumb_ptr<block_list> bl); +int battle_get_mdef2(dumb_ptr<block_list> bl); +interval_t battle_get_speed(dumb_ptr<block_list> bl); +interval_t battle_get_adelay(dumb_ptr<block_list> bl); +interval_t battle_get_amotion(dumb_ptr<block_list> bl); +interval_t battle_get_dmotion(dumb_ptr<block_list> bl); +LevelElement battle_get_element(dumb_ptr<block_list> bl); inline -Element battle_get_elem_type(struct block_list *bl) +Element battle_get_elem_type(dumb_ptr<block_list> bl) { return battle_get_element(bl).element; } -int battle_get_party_id(struct block_list *bl); -Race battle_get_race(struct block_list *bl); -MobMode battle_get_mode(struct block_list *bl); -int battle_get_stat(SP stat_id, struct block_list *bl); +int battle_get_party_id(dumb_ptr<block_list> bl); +Race battle_get_race(dumb_ptr<block_list> bl); +MobMode battle_get_mode(dumb_ptr<block_list> bl); +int battle_get_stat(SP stat_id, dumb_ptr<block_list> bl); -eptr<struct status_change, StatusChange> battle_get_sc_data(struct block_list *bl); -short *battle_get_sc_count(struct block_list *bl); -Opt1 *battle_get_opt1(struct block_list *bl); -Opt2 *battle_get_opt2(struct block_list *bl); -Opt3 *battle_get_opt3(struct block_list *bl); -Option *battle_get_option(struct block_list *bl); +eptr<struct status_change, StatusChange> battle_get_sc_data(dumb_ptr<block_list> bl); +short *battle_get_sc_count(dumb_ptr<block_list> bl); +Opt1 *battle_get_opt1(dumb_ptr<block_list> bl); +Opt2 *battle_get_opt2(dumb_ptr<block_list> bl); +Opt3 *battle_get_opt3(dumb_ptr<block_list> bl); +Option *battle_get_option(dumb_ptr<block_list> bl); bool battle_check_undead(Race race, Element element); -int battle_check_target(struct block_list *src, struct block_list *target, +int battle_check_target(dumb_ptr<block_list> src, dumb_ptr<block_list> target, BCT flag); -int battle_check_range(struct block_list *src, struct block_list *bl, +int battle_check_range(dumb_ptr<block_list> src, dumb_ptr<block_list> bl, int range); extern struct Battle_Config diff --git a/src/map/chrif.cpp b/src/map/chrif.cpp index 51736e4..aaa727e 100644 --- a/src/map/chrif.cpp +++ b/src/map/chrif.cpp @@ -97,7 +97,7 @@ int chrif_isconnect(void) * *------------------------------------------ */ -int chrif_save(struct map_session_data *sd) +int chrif_save(dumb_ptr<map_session_data> sd) { nullpo_retr(-1, sd); @@ -190,7 +190,7 @@ int chrif_recvmap(int fd) * マップ鯖間移動のためのデータ準備要求 *------------------------------------------ */ -int chrif_changemapserver(struct map_session_data *sd, char *name, int x, +int chrif_changemapserver(dumb_ptr<map_session_data> sd, char *name, int x, int y, struct in_addr ip, short port) { int i, s_ip; @@ -199,7 +199,7 @@ int chrif_changemapserver(struct map_session_data *sd, char *name, int x, s_ip = 0; for (i = 0; i < fd_max; i++) - if (session[i] && session[i]->session_data.get() == sd) + if (session[i] && dumb_ptr<map_session_data>(static_cast<map_session_data *>(session[i]->session_data.get())) == sd) { s_ip = session[i]->client_addr.sin_addr.s_addr; break; @@ -229,7 +229,7 @@ int chrif_changemapserver(struct map_session_data *sd, char *name, int x, static int chrif_changemapserverack(int fd) { - struct map_session_data *sd = map_id2sd(RFIFOL(fd, 2)); + dumb_ptr<map_session_data> sd = map_id2sd(RFIFOL(fd, 2)); if (sd == NULL || sd->status.char_id != RFIFOL(fd, 14)) return -1; @@ -300,7 +300,7 @@ int chrif_sendmapack(int fd) * *------------------------------------------ */ -int chrif_authreq(struct map_session_data *sd) +int chrif_authreq(dumb_ptr<map_session_data> sd) { int i; @@ -310,7 +310,7 @@ int chrif_authreq(struct map_session_data *sd) return -1; for (i = 0; i < fd_max; i++) - if (session[i] && session[i]->session_data.get() == sd) + if (session[i] && dumb_ptr<map_session_data>(static_cast<map_session_data *>(session[i]->session_data.get())) == sd) { WFIFOW(char_fd, 0) = 0x2afc; WFIFOL(char_fd, 2) = sd->bl_id; @@ -329,7 +329,7 @@ int chrif_authreq(struct map_session_data *sd) * *------------------------------------------ */ -int chrif_charselectreq(struct map_session_data *sd) +int chrif_charselectreq(dumb_ptr<map_session_data> sd) { int i, s_ip; @@ -340,7 +340,7 @@ int chrif_charselectreq(struct map_session_data *sd) s_ip = 0; for (i = 0; i < fd_max; i++) - if (session[i] && session[i]->session_data.get() == sd) + if (session[i] && dumb_ptr<map_session_data>(static_cast<map_session_data *>(session[i]->session_data.get())) == sd) { s_ip = session[i]->client_addr.sin_addr.s_addr; break; @@ -464,7 +464,7 @@ static int chrif_char_ask_name_answer(int fd) { int acc; - struct map_session_data *sd; + dumb_ptr<map_session_data> sd; char player_name[24]; acc = RFIFOL(fd, 2); // account_id of who has asked (-1 if nobody) @@ -606,7 +606,7 @@ static int chrif_changedgm(int fd) { int acc, level; - struct map_session_data *sd = NULL; + dumb_ptr<map_session_data> sd = NULL; acc = RFIFOL(fd, 2); level = RFIFOL(fd, 6); @@ -635,7 +635,7 @@ static int chrif_changedsex(int fd) { int acc, sex, i; - struct map_session_data *sd; + dumb_ptr<map_session_data> sd; acc = RFIFOL(fd, 2); sex = RFIFOL(fd, 6); @@ -678,7 +678,7 @@ int chrif_changedsex(int fd) * アカウント変数保存要求 *------------------------------------------ */ -int chrif_saveaccountreg2(struct map_session_data *sd) +int chrif_saveaccountreg2(dumb_ptr<map_session_data> sd) { int p, j; nullpo_retr(-1, sd); @@ -710,7 +710,7 @@ static int chrif_accountreg2(int fd) { int j, p; - struct map_session_data *sd; + dumb_ptr<map_session_data> sd; if ((sd = map_id2sd(RFIFOL(fd, 4))) == NULL) return 1; @@ -736,7 +736,7 @@ int chrif_accountreg2(int fd) static int chrif_divorce(int char_id, int partner_id) { - struct map_session_data *sd = NULL; + dumb_ptr<map_session_data> sd = NULL; if (!char_id || !partner_id) return 0; @@ -785,7 +785,7 @@ static int chrif_accountdeletion(int fd) { int acc; - struct map_session_data *sd; + dumb_ptr<map_session_data> sd; acc = RFIFOL(fd, 2); if (battle_config.etc_log) @@ -818,7 +818,7 @@ static int chrif_accountban(int fd) { int acc; - struct map_session_data *sd; + dumb_ptr<map_session_data> sd; acc = RFIFOL(fd, 2); if (battle_config.etc_log) @@ -941,7 +941,7 @@ void ladmin_itemfrob_fix_item(int source, int dest, struct item *item) } static -void ladmin_itemfrob_c2(struct block_list *bl, int source_id, int dest_id) +void ladmin_itemfrob_c2(dumb_ptr<block_list> bl, int source_id, int dest_id) { #define IFIX(v) if (v == source_id) {v = dest_id; } #define FIX(item) ladmin_itemfrob_fix_item(source_id, dest_id, &item) @@ -953,7 +953,7 @@ void ladmin_itemfrob_c2(struct block_list *bl, int source_id, int dest_id) { case BL::PC: { - struct map_session_data *pc = (struct map_session_data *) bl; + dumb_ptr<map_session_data> pc = bl->as_player(); struct storage *stor = account2storage2(pc->status.account_id); int j; @@ -988,7 +988,7 @@ void ladmin_itemfrob_c2(struct block_list *bl, int source_id, int dest_id) case BL::MOB: { - struct mob_data *mob = (struct mob_data *) bl; + dumb_ptr<mob_data> mob = bl->as_mob(); int i; for (i = 0; i < mob->lootitem_count; i++) FIX(mob->lootitem[i]); @@ -997,7 +997,7 @@ void ladmin_itemfrob_c2(struct block_list *bl, int source_id, int dest_id) case BL::ITEM: { - struct flooritem_data *item = (struct flooritem_data *) bl; + dumb_ptr<flooritem_data> item = bl->as_item(); FIX(item->item_data); break; } @@ -1007,7 +1007,7 @@ void ladmin_itemfrob_c2(struct block_list *bl, int source_id, int dest_id) } static -void ladmin_itemfrob_c(struct block_list *bl, int source_id, int dest_id) +void ladmin_itemfrob_c(dumb_ptr<block_list> bl, int source_id, int dest_id) { ladmin_itemfrob_c2(bl, source_id, dest_id); } @@ -1017,7 +1017,7 @@ void ladmin_itemfrob(int fd) { int source_id = RFIFOL(fd, 2); int dest_id = RFIFOL(fd, 6); - struct block_list *bl = (struct block_list *) map_get_first_session(); + dumb_ptr<block_list> bl = (dumb_ptr<block_list>) map_get_first_session(); // flooritems map_foreachobject(std::bind(ladmin_itemfrob_c, ph::_1, source_id, dest_id), BL::NUL /* any object */); @@ -1171,7 +1171,7 @@ void send_users_tochar(TimerData *, tick_t) { if (!session[i]) continue; - map_session_data *sd = static_cast<map_session_data *>(session[i]->session_data.get()); + dumb_ptr<map_session_data> sd = dumb_ptr<map_session_data>(static_cast<map_session_data *>(session[i]->session_data.get())); if (sd && sd->state.auth && !((battle_config.hide_GM_session || sd->state.shroud_active diff --git a/src/map/chrif.hpp b/src/map/chrif.hpp index 2816e9f..6dca70c 100644 --- a/src/map/chrif.hpp +++ b/src/map/chrif.hpp @@ -1,6 +1,10 @@ #ifndef CHRIF_HPP #define CHRIF_HPP +#include "../common/dumb_ptr.hpp" + +#include "map.hpp" + void chrif_setuserid(const char *); void chrif_setpasswd(const char *); char *chrif_getpasswd(void); @@ -10,11 +14,11 @@ void chrif_setport(int); int chrif_isconnect(void); -int chrif_authreq(struct map_session_data *); -int chrif_save(struct map_session_data *); -int chrif_charselectreq(struct map_session_data *); +int chrif_authreq(dumb_ptr<map_session_data>); +int chrif_save(dumb_ptr<map_session_data>); +int chrif_charselectreq(dumb_ptr<map_session_data>); -int chrif_changemapserver(struct map_session_data *sd, +int chrif_changemapserver(dumb_ptr<map_session_data> sd, char *name, int x, int y, struct in_addr ip, short port); @@ -24,7 +28,7 @@ int chrif_changeemail(int id, const char *actual_email, const char *new_email); int chrif_char_ask_name(int id, char *character_name, short operation_type, int year, int month, int day, int hour, int minute, int second); -int chrif_saveaccountreg2(struct map_session_data *sd); +int chrif_saveaccountreg2(dumb_ptr<map_session_data> sd); int chrif_reloadGMdb(void); int chrif_send_divorce(int char_id); diff --git a/src/map/clif.cpp b/src/map/clif.cpp index 8419c7d..fbba044 100644 --- a/src/map/clif.cpp +++ b/src/map/clif.cpp @@ -40,7 +40,7 @@ constexpr int EMOTE_IGNORED = 0x0e; // 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); +typedef void (*clif_func)(int fd, dumb_ptr<map_session_data> sd); struct func_table { interval_t rate; @@ -114,8 +114,8 @@ static int map_port = 5121; static -int clif_changelook_towards(struct block_list *bl, LOOK type, int val, - struct map_session_data *dstsd); +int clif_changelook_towards(dumb_ptr<block_list> bl, LOOK type, int val, + dumb_ptr<map_session_data> dstsd); /*========================================== * map鯖のip設定 @@ -166,7 +166,7 @@ int clif_countusers(void) { if (!session[i]) continue; - map_session_data *sd = static_cast<map_session_data *>(session[i]->session_data.get()); + dumb_ptr<map_session_data> sd = dumb_ptr<map_session_data>(static_cast<map_session_data *>(session[i]->session_data.get())); if (sd && sd->state.auth && !(battle_config.hide_GM_session && pc_isGM(sd))) users++; } @@ -177,13 +177,13 @@ int clif_countusers(void) * 全てのclientに対してfunc()実行 *------------------------------------------ */ -int clif_foreachclient(std::function<void (struct map_session_data *)> func) +int clif_foreachclient(std::function<void (dumb_ptr<map_session_data>)> func) { for (int i = 0; i < fd_max; i++) { if (!session[i]) continue; - map_session_data *sd = static_cast<map_session_data *>(session[i]->session_data.get()); + dumb_ptr<map_session_data> sd = dumb_ptr<map_session_data>(static_cast<map_session_data *>(session[i]->session_data.get())); if (sd && sd->state.auth) func(sd); } @@ -191,20 +191,20 @@ int clif_foreachclient(std::function<void (struct map_session_data *)> func) } static -int is_deaf(struct block_list *bl) +int is_deaf(dumb_ptr<block_list> bl) { - struct map_session_data *sd = (struct map_session_data *) bl; if (!bl || bl->bl_type != BL::PC) return 0; + dumb_ptr<map_session_data> sd = bl->as_player(); return sd->special_state.deaf; } static -void clif_emotion_towards(struct block_list *bl, - struct block_list *target, int type); +void clif_emotion_towards(dumb_ptr<block_list> bl, + dumb_ptr<block_list> target, int type); static -char *clif_validate_chat(struct map_session_data *sd, int type, +char *clif_validate_chat(dumb_ptr<map_session_data> sd, int type, const char **message, size_t *message_len); /*========================================== @@ -212,11 +212,11 @@ char *clif_validate_chat(struct map_session_data *sd, int type, *------------------------------------------ */ static -void clif_send_sub(struct block_list *bl, const unsigned char *buf, int len, - struct block_list *src_bl, SendWho type) +void clif_send_sub(dumb_ptr<block_list> bl, const unsigned char *buf, int len, + dumb_ptr<block_list> src_bl, SendWho type) { nullpo_retv(bl); - struct map_session_data *sd = (struct map_session_data *) bl; + dumb_ptr<map_session_data> sd = bl->as_player(); switch (type) { @@ -228,7 +228,7 @@ void clif_send_sub(struct block_list *bl, const unsigned char *buf, int len, case SendWho::AREA_CHAT_WOC: if (is_deaf(bl) && !(bl->bl_type == BL::PC - && pc_isGM((struct map_session_data *) src_bl))) + && pc_isGM(src_bl->as_player()))) { clif_emotion_towards(src_bl, bl, EMOTE_IGNORED); return; @@ -266,7 +266,7 @@ void clif_send_sub(struct block_list *bl, const unsigned char *buf, int len, *------------------------------------------ */ static -int clif_send(const uint8_t *buf, int len, struct block_list *bl, SendWho type) +int clif_send(const uint8_t *buf, int len, dumb_ptr<block_list> bl, SendWho type) { struct party *p = NULL; int x0 = 0, x1 = 0, y0 = 0, y1 = 0; @@ -277,7 +277,7 @@ int clif_send(const uint8_t *buf, int len, struct block_list *bl, SendWho type) if (bl->bl_type == BL::PC) { - struct map_session_data *sd2 = (struct map_session_data *) bl; + dumb_ptr<map_session_data> sd2 = bl->as_player(); if (bool(sd2->status.option & Option::INVISIBILITY)) { // Obscure hidden GMs @@ -305,7 +305,7 @@ int clif_send(const uint8_t *buf, int len, struct block_list *bl, SendWho type) { if (!session[i]) continue; - map_session_data *sd = static_cast<map_session_data *>(session[i]->session_data.get()); + dumb_ptr<map_session_data> sd = dumb_ptr<map_session_data>(static_cast<map_session_data *>(session[i]->session_data.get())); if (sd && sd->state.auth) { if (clif_parse_func_table[RBUFW(buf, 0)].len) @@ -322,7 +322,7 @@ int clif_send(const uint8_t *buf, int len, struct block_list *bl, SendWho type) { if (!session[i]) continue; - map_session_data *sd = static_cast<map_session_data *>(session[i]->session_data.get()); + dumb_ptr<map_session_data> sd = dumb_ptr<map_session_data>(static_cast<map_session_data *>(session[i]->session_data.get())); if (sd && sd->state.auth && sd->bl_m == bl->bl_m) { if (clif_parse_func_table[RBUFW(buf, 0)].len) @@ -359,7 +359,7 @@ int clif_send(const uint8_t *buf, int len, struct block_list *bl, SendWho type) case SendWho::PARTY_SAMEMAP_WOS: // 自分以外の同じマップの全パーティーメンバに送信 if (bl->bl_type == BL::PC) { - struct map_session_data *sd = (struct map_session_data *) bl; + dumb_ptr<map_session_data> sd = bl->as_player(); if (sd->partyspy > 0) { p = party_search(sd->partyspy); @@ -374,7 +374,7 @@ int clif_send(const uint8_t *buf, int len, struct block_list *bl, SendWho type) { for (int i = 0; i < MAX_PARTY; i++) { - struct map_session_data *sd = p->member[i].sd; + dumb_ptr<map_session_data> sd = dumb_ptr<map_session_data>(p->member[i].sd); if (sd) { if (sd->bl_id == bl->bl_id && (type == SendWho::PARTY_WOS || @@ -399,7 +399,7 @@ int clif_send(const uint8_t *buf, int len, struct block_list *bl, SendWho type) { if (!session[i]) continue; - map_session_data *sd = static_cast<map_session_data *>(session[i]->session_data.get()); + dumb_ptr<map_session_data> sd = dumb_ptr<map_session_data>(static_cast<map_session_data *>(session[i]->session_data.get())); if (sd && sd->state.auth) { if (sd->partyspy == p->party_id) @@ -417,7 +417,7 @@ int clif_send(const uint8_t *buf, int len, struct block_list *bl, SendWho type) break; case SendWho::SELF: { - map_session_data *sd = (struct map_session_data *) bl; + dumb_ptr<map_session_data> sd = bl->as_player(); if (clif_parse_func_table[RBUFW(buf, 0)].len) { // packet must exist @@ -443,7 +443,7 @@ int clif_send(const uint8_t *buf, int len, struct block_list *bl, SendWho type) * *------------------------------------------ */ -int clif_authok(struct map_session_data *sd) +int clif_authok(dumb_ptr<map_session_data> sd) { int fd; @@ -491,7 +491,7 @@ int clif_authfail_fd(int fd, int type) */ int clif_charselectok(int id) { - struct map_session_data *sd; + dumb_ptr<map_session_data> sd; int fd; if ((sd = map_id2sd(id)) == NULL) @@ -513,7 +513,7 @@ int clif_charselectok(int id) *------------------------------------------ */ static -int clif_set009e(struct flooritem_data *fitem, uint8_t *buf) +int clif_set009e(dumb_ptr<flooritem_data> fitem, uint8_t *buf) { int view; @@ -540,7 +540,7 @@ int clif_set009e(struct flooritem_data *fitem, uint8_t *buf) * *------------------------------------------ */ -int clif_dropflooritem(struct flooritem_data *fitem) +int clif_dropflooritem(dumb_ptr<flooritem_data> fitem) { uint8_t buf[64]; @@ -558,7 +558,7 @@ int clif_dropflooritem(struct flooritem_data *fitem) * *------------------------------------------ */ -int clif_clearflooritem(struct flooritem_data *fitem, int fd) +int clif_clearflooritem(dumb_ptr<flooritem_data> fitem, int fd) { unsigned char buf[16]; @@ -584,7 +584,7 @@ int clif_clearflooritem(struct flooritem_data *fitem, int fd) * *------------------------------------------ */ -int clif_clearchar(struct block_list *bl, BeingRemoveWhy type) +int clif_clearchar(dumb_ptr<block_list> bl, BeingRemoveWhy type) { unsigned char buf[16]; @@ -609,19 +609,27 @@ int clif_clearchar(struct block_list *bl, BeingRemoveWhy type) static void clif_clearchar_delay_sub(TimerData *, tick_t, - struct block_list *bl, BeingRemoveWhy type) + dumb_ptr<block_list> bl, BeingRemoveWhy type) { clif_clearchar(bl, type); MapBlockLock::freeblock(bl); } int clif_clearchar_delay(tick_t tick, - struct block_list *bl, BeingRemoveWhy type) + dumb_ptr<block_list> bl, BeingRemoveWhy type) { - struct block_list *tmpbl; - CREATE(tmpbl, struct block_list, 1); + dumb_ptr<block_list> tmpbl; + tmpbl.new_(); + + // yikes! + tmpbl->bl_next = bl->bl_next; + tmpbl->bl_prev = bl->bl_prev; + tmpbl->bl_id = bl->bl_id; + tmpbl->bl_m = bl->bl_m; + tmpbl->bl_x = bl->bl_x; + tmpbl->bl_y = bl->bl_y; + tmpbl->bl_type = bl->bl_type; - memcpy(tmpbl, bl, sizeof(struct block_list)); Timer(tick, std::bind(clif_clearchar_delay_sub, ph::_1, ph::_2, tmpbl, type) @@ -652,7 +660,7 @@ int clif_clearchar_id(int id, BeingRemoveWhy type, int fd) *------------------------------------------ */ static -int clif_set0078(struct map_session_data *sd, unsigned char *buf) +int clif_set0078(dumb_ptr<map_session_data> sd, unsigned char *buf) { nullpo_ret(sd); @@ -720,7 +728,7 @@ int clif_set0078(struct map_session_data *sd, unsigned char *buf) *------------------------------------------ */ static -int clif_set007b(struct map_session_data *sd, unsigned char *buf) +int clif_set007b(dumb_ptr<map_session_data> sd, unsigned char *buf) { nullpo_ret(sd); @@ -779,7 +787,7 @@ int clif_set007b(struct map_session_data *sd, unsigned char *buf) *------------------------------------------ */ static -int clif_mob0078(struct mob_data *md, unsigned char *buf) +int clif_mob0078(dumb_ptr<mob_data> md, unsigned char *buf) { int level; @@ -814,7 +822,7 @@ int clif_mob0078(struct mob_data *md, unsigned char *buf) *------------------------------------------ */ static -int clif_mob007b(struct mob_data *md, unsigned char *buf) +int clif_mob007b(dumb_ptr<mob_data> md, unsigned char *buf) { int level; @@ -848,7 +856,7 @@ int clif_mob007b(struct mob_data *md, unsigned char *buf) *------------------------------------------ */ static -int clif_npc0078(struct npc_data *nd, unsigned char *buf) +int clif_npc0078(dumb_ptr<npc_data> nd, unsigned char *buf) { nullpo_ret(nd); @@ -892,7 +900,7 @@ earray<EQUIP, LOOK, LOOK::COUNT> equip_points //= * *------------------------------------------ */ -int clif_spawnpc(struct map_session_data *sd) +int clif_spawnpc(dumb_ptr<map_session_data> sd) { unsigned char buf[128]; @@ -924,7 +932,7 @@ int clif_spawnpc(struct map_session_data *sd) * *------------------------------------------ */ -int clif_spawnnpc(struct npc_data *nd) +int clif_spawnnpc(dumb_ptr<npc_data> nd) { unsigned char buf[64]; int len; @@ -950,7 +958,7 @@ int clif_spawnnpc(struct npc_data *nd) return 0; } -int clif_spawn_fake_npc_for_player(struct map_session_data *sd, int fake_npc_id) +int clif_spawn_fake_npc_for_player(dumb_ptr<map_session_data> sd, int fake_npc_id) { int fd; @@ -991,7 +999,7 @@ int clif_spawn_fake_npc_for_player(struct map_session_data *sd, int fake_npc_id) * *------------------------------------------ */ -int clif_spawnmob(struct mob_data *md) +int clif_spawnmob(dumb_ptr<mob_data> md) { unsigned char buf[64]; int len; @@ -1023,7 +1031,7 @@ int clif_spawnmob(struct mob_data *md) *------------------------------------------ */ static -int clif_servertick(struct map_session_data *sd) +int clif_servertick(dumb_ptr<map_session_data> sd) { int fd; @@ -1041,7 +1049,7 @@ int clif_servertick(struct map_session_data *sd) * *------------------------------------------ */ -int clif_walkok(struct map_session_data *sd) +int clif_walkok(dumb_ptr<map_session_data> sd) { int fd; @@ -1061,7 +1069,7 @@ int clif_walkok(struct map_session_data *sd) * *------------------------------------------ */ -int clif_movechar(struct map_session_data *sd) +int clif_movechar(dumb_ptr<map_session_data> sd) { int len; unsigned char buf[256]; @@ -1084,7 +1092,7 @@ int clif_movechar(struct map_session_data *sd) *------------------------------------------ */ static -void clif_quitsave(int, struct map_session_data *sd) +void clif_quitsave(int, dumb_ptr<map_session_data> sd) { map_quit(sd); } @@ -1118,7 +1126,7 @@ void clif_setwaitclose(int fd) * *------------------------------------------ */ -int clif_changemap(struct map_session_data *sd, const char *mapname, int x, int y) +int clif_changemap(dumb_ptr<map_session_data> sd, const char *mapname, int x, int y) { int fd; @@ -1139,7 +1147,7 @@ int clif_changemap(struct map_session_data *sd, const char *mapname, int x, int * *------------------------------------------ */ -int clif_changemapserver(struct map_session_data *sd, const char *mapname, int x, +int clif_changemapserver(dumb_ptr<map_session_data> sd, const char *mapname, int x, int y, struct in_addr ip, int port) { int fd; @@ -1162,7 +1170,7 @@ int clif_changemapserver(struct map_session_data *sd, const char *mapname, int x * *------------------------------------------ */ -int clif_fixpos(struct block_list *bl) +int clif_fixpos(dumb_ptr<block_list> bl) { uint8_t buf[16]; @@ -1182,7 +1190,7 @@ int clif_fixpos(struct block_list *bl) * *------------------------------------------ */ -int clif_npcbuysell(struct map_session_data *sd, int id) +int clif_npcbuysell(dumb_ptr<map_session_data> sd, int id) { int fd; @@ -1200,7 +1208,7 @@ int clif_npcbuysell(struct map_session_data *sd, int id) * *------------------------------------------ */ -int clif_buylist(struct map_session_data *sd, struct npc_data *nd) +int clif_buylist(dumb_ptr<map_session_data> sd, dumb_ptr<npc_data_shop> nd) { struct item_data *id; int fd, i, val; @@ -1210,17 +1218,17 @@ int clif_buylist(struct map_session_data *sd, struct npc_data *nd) fd = sd->fd; WFIFOW(fd, 0) = 0xc6; - for (i = 0; nd->u.shop_item[i].nameid > 0; i++) + for (i = 0; i < nd->shop_items.size(); i++) { - id = itemdb_search(nd->u.shop_item[i].nameid); - val = nd->u.shop_item[i].value; + id = itemdb_search(nd->shop_items[i].nameid); + val = nd->shop_items[i].value; WFIFOL(fd, 4 + i * 11) = val; // base price WFIFOL(fd, 8 + i * 11) = val; // actual price WFIFOB(fd, 12 + i * 11) = uint8_t(id->type); if (id->view_id > 0) WFIFOW(fd, 13 + i * 11) = id->view_id; else - WFIFOW(fd, 13 + i * 11) = nd->u.shop_item[i].nameid; + WFIFOW(fd, 13 + i * 11) = nd->shop_items[i].nameid; } WFIFOW(fd, 2) = i * 11 + 4; WFIFOSET(fd, WFIFOW(fd, 2)); @@ -1232,7 +1240,7 @@ int clif_buylist(struct map_session_data *sd, struct npc_data *nd) * *------------------------------------------ */ -int clif_selllist(struct map_session_data *sd) +int clif_selllist(dumb_ptr<map_session_data> sd) { int fd, i, c = 0, val; @@ -1263,7 +1271,7 @@ int clif_selllist(struct map_session_data *sd) * *------------------------------------------ */ -int clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes) +int clif_scriptmes(dumb_ptr<map_session_data> sd, int npcid, const char *mes) { int fd; @@ -1283,7 +1291,7 @@ int clif_scriptmes(struct map_session_data *sd, int npcid, const char *mes) * *------------------------------------------ */ -int clif_scriptnext(struct map_session_data *sd, int npcid) +int clif_scriptnext(dumb_ptr<map_session_data> sd, int npcid) { int fd; @@ -1301,7 +1309,7 @@ int clif_scriptnext(struct map_session_data *sd, int npcid) * *------------------------------------------ */ -int clif_scriptclose(struct map_session_data *sd, int npcid) +int clif_scriptclose(dumb_ptr<map_session_data> sd, int npcid) { int fd; @@ -1319,7 +1327,7 @@ int clif_scriptclose(struct map_session_data *sd, int npcid) * *------------------------------------------ */ -int clif_scriptmenu(struct map_session_data *sd, int npcid, const char *mes) +int clif_scriptmenu(dumb_ptr<map_session_data> sd, int npcid, const char *mes) { int fd; @@ -1339,7 +1347,7 @@ int clif_scriptmenu(struct map_session_data *sd, int npcid, const char *mes) * *------------------------------------------ */ -int clif_scriptinput(struct map_session_data *sd, int npcid) +int clif_scriptinput(dumb_ptr<map_session_data> sd, int npcid) { int fd; @@ -1357,7 +1365,7 @@ int clif_scriptinput(struct map_session_data *sd, int npcid) * *------------------------------------------ */ -int clif_scriptinputstr(struct map_session_data *sd, int npcid) +int clif_scriptinputstr(dumb_ptr<map_session_data> sd, int npcid) { int fd; @@ -1375,7 +1383,7 @@ int clif_scriptinputstr(struct map_session_data *sd, int npcid) * *------------------------------------------ */ -int clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, +int clif_viewpoint(dumb_ptr<map_session_data> sd, int npc_id, int type, int x, int y, int id, int color) { int fd; @@ -1399,7 +1407,7 @@ int clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, * *------------------------------------------ */ -int clif_cutin(struct map_session_data *sd, const char *image, int type) +int clif_cutin(dumb_ptr<map_session_data> sd, const char *image, int type) { int fd; @@ -1418,7 +1426,7 @@ int clif_cutin(struct map_session_data *sd, const char *image, int type) * *------------------------------------------ */ -int clif_additem(struct map_session_data *sd, int n, int amount, PickupFail fail) +int clif_additem(dumb_ptr<map_session_data> sd, int n, int amount, PickupFail fail) { nullpo_ret(sd); @@ -1507,7 +1515,7 @@ int clif_additem(struct map_session_data *sd, int n, int amount, PickupFail fail * *------------------------------------------ */ -int clif_delitem(struct map_session_data *sd, int n, int amount) +int clif_delitem(dumb_ptr<map_session_data> sd, int n, int amount) { int fd; @@ -1527,7 +1535,7 @@ int clif_delitem(struct map_session_data *sd, int n, int amount) * *------------------------------------------ */ -int clif_itemlist(struct map_session_data *sd) +int clif_itemlist(dumb_ptr<map_session_data> sd) { nullpo_ret(sd); @@ -1577,7 +1585,7 @@ int clif_itemlist(struct map_session_data *sd) * *------------------------------------------ */ -int clif_equiplist(struct map_session_data *sd) +int clif_equiplist(dumb_ptr<map_session_data> sd) { nullpo_ret(sd); @@ -1654,7 +1662,7 @@ int clif_equiplist(struct map_session_data *sd) * カプラさんに預けてある消耗品&収集品リスト *------------------------------------------ */ -int clif_storageitemlist(struct map_session_data *sd, struct storage *stor) +int clif_storageitemlist(dumb_ptr<map_session_data> sd, struct storage *stor) { nullpo_ret(sd); nullpo_ret(stor); @@ -1700,7 +1708,7 @@ int clif_storageitemlist(struct map_session_data *sd, struct storage *stor) * カプラさんに預けてある装備リスト *------------------------------------------ */ -int clif_storageequiplist(struct map_session_data *sd, struct storage *stor) +int clif_storageequiplist(dumb_ptr<map_session_data> sd, struct storage *stor) { nullpo_ret(sd); nullpo_ret(stor); @@ -1780,7 +1788,7 @@ int clif_storageequiplist(struct map_session_data *sd, struct storage *stor) * 表示専用数字はこの中で計算して送る *------------------------------------------ */ -int clif_updatestatus(struct map_session_data *sd, SP type) +int clif_updatestatus(dumb_ptr<map_session_data> sd, SP type) { int fd, len = 8; @@ -1951,21 +1959,21 @@ int clif_updatestatus(struct map_session_data *sd, SP type) * *------------------------------------------ */ -int clif_changelook(struct block_list *bl, LOOK type, int val) +int clif_changelook(dumb_ptr<block_list> bl, LOOK type, int val) { return clif_changelook_towards(bl, type, val, NULL); } -int clif_changelook_towards(struct block_list *bl, LOOK type, int val, - struct map_session_data *dstsd) +int clif_changelook_towards(dumb_ptr<block_list> bl, LOOK type, int val, + dumb_ptr<map_session_data> dstsd) { unsigned char buf[32]; - struct map_session_data *sd = NULL; + dumb_ptr<map_session_data> sd = NULL; nullpo_ret(bl); if (bl->bl_type == BL::PC) - sd = (struct map_session_data *) bl; + sd = bl->as_player(); if (sd && bool(sd->status.option & Option::INVISIBILITY)) return 0; @@ -2056,7 +2064,7 @@ int clif_changelook_towards(struct block_list *bl, LOOK type, int val, *------------------------------------------ */ static -int clif_initialstatus(struct map_session_data *sd) +int clif_initialstatus(dumb_ptr<map_session_data> sd) { nullpo_ret(sd); @@ -2112,7 +2120,7 @@ int clif_initialstatus(struct map_session_data *sd) *矢装備 *------------------------------------------ */ -int clif_arrowequip(struct map_session_data *sd, int val) +int clif_arrowequip(dumb_ptr<map_session_data> sd, int val) { int fd; @@ -2134,7 +2142,7 @@ int clif_arrowequip(struct map_session_data *sd, int val) * *------------------------------------------ */ -int clif_arrow_fail(struct map_session_data *sd, int type) +int clif_arrow_fail(dumb_ptr<map_session_data> sd, int type) { int fd; @@ -2153,7 +2161,7 @@ int clif_arrow_fail(struct map_session_data *sd, int type) * *------------------------------------------ */ -int clif_statusupack(struct map_session_data *sd, SP type, int ok, int val) +int clif_statusupack(dumb_ptr<map_session_data> sd, SP type, int ok, int val) { int fd; @@ -2173,7 +2181,7 @@ int clif_statusupack(struct map_session_data *sd, SP type, int ok, int val) * *------------------------------------------ */ -int clif_equipitemack(struct map_session_data *sd, int n, EPOS pos, int ok) +int clif_equipitemack(dumb_ptr<map_session_data> sd, int n, EPOS pos, int ok) { int fd; @@ -2193,7 +2201,7 @@ int clif_equipitemack(struct map_session_data *sd, int n, EPOS pos, int ok) * *------------------------------------------ */ -int clif_unequipitemack(struct map_session_data *sd, int n, EPOS pos, int ok) +int clif_unequipitemack(dumb_ptr<map_session_data> sd, int n, EPOS pos, int ok) { int fd; @@ -2213,7 +2221,7 @@ int clif_unequipitemack(struct map_session_data *sd, int n, EPOS pos, int ok) * *------------------------------------------ */ -int clif_misceffect(struct block_list *bl, int type) +int clif_misceffect(dumb_ptr<block_list> bl, int type) { uint8_t buf[32]; @@ -2232,7 +2240,7 @@ int clif_misceffect(struct block_list *bl, int type) * 表示オプション変更 *------------------------------------------ */ -int clif_changeoption(struct block_list *bl) +int clif_changeoption(dumb_ptr<block_list> bl) { uint8_t buf[32]; eptr<struct status_change, StatusChange> sc_data; @@ -2258,7 +2266,7 @@ int clif_changeoption(struct block_list *bl) * *------------------------------------------ */ -int clif_useitemack(struct map_session_data *sd, int index, int amount, +int clif_useitemack(dumb_ptr<map_session_data> sd, int index, int amount, int ok) { nullpo_ret(sd); @@ -2296,7 +2304,7 @@ int clif_useitemack(struct map_session_data *sd, int index, int amount, * 取り引き要請受け *------------------------------------------ */ -int clif_traderequest(struct map_session_data *sd, const char *name) +int clif_traderequest(dumb_ptr<map_session_data> sd, const char *name) { int fd; @@ -2314,7 +2322,7 @@ int clif_traderequest(struct map_session_data *sd, const char *name) * 取り引き要求応答 *------------------------------------------ */ -int clif_tradestart(struct map_session_data *sd, int type) +int clif_tradestart(dumb_ptr<map_session_data> sd, int type) { int fd; @@ -2332,8 +2340,8 @@ int clif_tradestart(struct map_session_data *sd, int type) * 相手方からのアイテム追加 *------------------------------------------ */ -int clif_tradeadditem(struct map_session_data *sd, - struct map_session_data *tsd, int index, int amount) +int clif_tradeadditem(dumb_ptr<map_session_data> sd, + dumb_ptr<map_session_data> tsd, int index, int amount) { int fd, j; @@ -2414,7 +2422,7 @@ int clif_tradeadditem(struct map_session_data *sd, * アイテム追加成功/失敗 *------------------------------------------ */ -int clif_tradeitemok(struct map_session_data *sd, int index, int amount, +int clif_tradeitemok(dumb_ptr<map_session_data> sd, int index, int amount, int fail) { int fd; @@ -2435,7 +2443,7 @@ int clif_tradeitemok(struct map_session_data *sd, int index, int amount, * 取り引きok押し *------------------------------------------ */ -int clif_tradedeal_lock(struct map_session_data *sd, int fail) +int clif_tradedeal_lock(dumb_ptr<map_session_data> sd, int fail) { int fd; @@ -2453,7 +2461,7 @@ int clif_tradedeal_lock(struct map_session_data *sd, int fail) * 取り引きがキャンセルされました *------------------------------------------ */ -int clif_tradecancelled(struct map_session_data *sd) +int clif_tradecancelled(dumb_ptr<map_session_data> sd) { int fd; @@ -2470,7 +2478,7 @@ int clif_tradecancelled(struct map_session_data *sd) * 取り引き完了 *------------------------------------------ */ -int clif_tradecompleted(struct map_session_data *sd, int fail) +int clif_tradecompleted(dumb_ptr<map_session_data> sd, int fail) { int fd; @@ -2488,7 +2496,7 @@ int clif_tradecompleted(struct map_session_data *sd, int fail) * カプラ倉庫のアイテム数を更新 *------------------------------------------ */ -int clif_updatestorageamount(struct map_session_data *sd, +int clif_updatestorageamount(dumb_ptr<map_session_data> sd, struct storage *stor) { int fd; @@ -2509,7 +2517,7 @@ int clif_updatestorageamount(struct map_session_data *sd, * カプラ倉庫にアイテムを追加する *------------------------------------------ */ -int clif_storageitemadded(struct map_session_data *sd, struct storage *stor, +int clif_storageitemadded(dumb_ptr<map_session_data> sd, struct storage *stor, int index, int amount) { int fd, j; @@ -2572,7 +2580,7 @@ int clif_storageitemadded(struct map_session_data *sd, struct storage *stor, * カプラ倉庫からアイテムを取り去る *------------------------------------------ */ -int clif_storageitemremoved(struct map_session_data *sd, int index, +int clif_storageitemremoved(dumb_ptr<map_session_data> sd, int index, int amount) { int fd; @@ -2592,7 +2600,7 @@ int clif_storageitemremoved(struct map_session_data *sd, int index, * カプラ倉庫を閉じる *------------------------------------------ */ -int clif_storageclose(struct map_session_data *sd) +int clif_storageclose(dumb_ptr<map_session_data> sd) { int fd; @@ -2605,8 +2613,8 @@ int clif_storageclose(struct map_session_data *sd) return 0; } -void clif_changelook_accessories(struct block_list *bl, - struct map_session_data *dest) +void clif_changelook_accessories(dumb_ptr<block_list> bl, + dumb_ptr<map_session_data> dest) { for (LOOK i = LOOK::SHOES; i < LOOK::COUNT; i = LOOK(uint8_t(i) + 1)) clif_changelook_towards(bl, i, 0, dest); @@ -2620,8 +2628,8 @@ void clif_changelook_accessories(struct block_list *bl, *------------------------------------------ */ static -void clif_getareachar_pc(struct map_session_data *sd, - struct map_session_data *dstsd) +void clif_getareachar_pc(dumb_ptr<map_session_data> sd, + dumb_ptr<map_session_data> dstsd) { int len; @@ -2655,7 +2663,7 @@ void clif_getareachar_pc(struct map_session_data *sd, *------------------------------------------ */ static -void clif_getareachar_npc(struct map_session_data *sd, struct npc_data *nd) +void clif_getareachar_npc(dumb_ptr<map_session_data> sd, dumb_ptr<npc_data> nd) { int len; @@ -2673,7 +2681,7 @@ void clif_getareachar_npc(struct map_session_data *sd, struct npc_data *nd) * 移動停止 *------------------------------------------ */ -int clif_movemob(struct mob_data *md) +int clif_movemob(dumb_ptr<mob_data> md) { unsigned char buf[256]; int len; @@ -2690,7 +2698,7 @@ int clif_movemob(struct mob_data *md) * モンスターの位置修正 *------------------------------------------ */ -int clif_fixmobpos(struct mob_data *md) +int clif_fixmobpos(dumb_ptr<mob_data> md) { unsigned char buf[256]; int len; @@ -2715,7 +2723,7 @@ int clif_fixmobpos(struct mob_data *md) * PCの位置修正 *------------------------------------------ */ -int clif_fixpcpos(struct map_session_data *sd) +int clif_fixpcpos(dumb_ptr<map_session_data> sd) { unsigned char buf[256]; int len; @@ -2741,7 +2749,7 @@ int clif_fixpcpos(struct map_session_data *sd) * 通常攻撃エフェクト&ダメージ *------------------------------------------ */ -int clif_damage(struct block_list *src, struct block_list *dst, +int clif_damage(dumb_ptr<block_list> src, dumb_ptr<block_list> dst, tick_t tick, interval_t sdelay, interval_t ddelay, int damage, int div, DamageType type, int damage2) { @@ -2773,7 +2781,7 @@ int clif_damage(struct block_list *src, struct block_list *dst, *------------------------------------------ */ static -void clif_getareachar_mob(struct map_session_data *sd, struct mob_data *md) +void clif_getareachar_mob(dumb_ptr<map_session_data> sd, dumb_ptr<mob_data> md) { int len; nullpo_retv(sd); @@ -2796,8 +2804,8 @@ void clif_getareachar_mob(struct map_session_data *sd, struct mob_data *md) *------------------------------------------ */ static -void clif_getareachar_item(struct map_session_data *sd, - struct flooritem_data *fitem) +void clif_getareachar_item(dumb_ptr<map_session_data> sd, + dumb_ptr<flooritem_data> fitem) { int view, fd; @@ -2827,25 +2835,25 @@ void clif_getareachar_item(struct map_session_data *sd, *------------------------------------------ */ static -void clif_getareachar(struct block_list *bl, struct map_session_data *sd) +void clif_getareachar(dumb_ptr<block_list> bl, dumb_ptr<map_session_data> sd) { nullpo_retv(bl); switch (bl->bl_type) { case BL::PC: - if (sd == (struct map_session_data *) bl) + if (sd == bl->as_player()) break; - clif_getareachar_pc(sd, (struct map_session_data *) bl); + clif_getareachar_pc(sd, bl->as_player()); break; case BL::NPC: - clif_getareachar_npc(sd, (struct npc_data *) bl); + clif_getareachar_npc(sd, bl->as_npc()); break; case BL::MOB: - clif_getareachar_mob(sd, (struct mob_data *) bl); + clif_getareachar_mob(sd, bl->as_mob()); break; case BL::ITEM: - clif_getareachar_item(sd, (struct flooritem_data *) bl); + clif_getareachar_item(sd, bl->as_item()); break; default: if (battle_config.error_log) @@ -2859,9 +2867,9 @@ void clif_getareachar(struct block_list *bl, struct map_session_data *sd) * *------------------------------------------ */ -void clif_pcoutsight(struct block_list *bl, struct map_session_data *sd) +void clif_pcoutsight(dumb_ptr<block_list> bl, dumb_ptr<map_session_data> sd) { - struct map_session_data *dstsd; + dumb_ptr<map_session_data> dstsd; nullpo_retv(bl); nullpo_retv(sd); @@ -2869,7 +2877,7 @@ void clif_pcoutsight(struct block_list *bl, struct map_session_data *sd) switch (bl->bl_type) { case BL::PC: - dstsd = (struct map_session_data *) bl; + dstsd = bl->as_player(); if (sd != dstsd) { clif_clearchar_id(dstsd->bl_id, BeingRemoveWhy::GONE, sd->fd); @@ -2877,14 +2885,14 @@ void clif_pcoutsight(struct block_list *bl, struct map_session_data *sd) } break; case BL::NPC: - if (((struct npc_data *) bl)->npc_class != INVISIBLE_CLASS) + if (bl->as_npc()->npc_class != INVISIBLE_CLASS) clif_clearchar_id(bl->bl_id, BeingRemoveWhy::GONE, sd->fd); break; case BL::MOB: clif_clearchar_id(bl->bl_id, BeingRemoveWhy::GONE, sd->fd); break; case BL::ITEM: - clif_clearflooritem((struct flooritem_data *) bl, sd->fd); + clif_clearflooritem(bl->as_item(), sd->fd); break; } } @@ -2893,9 +2901,9 @@ void clif_pcoutsight(struct block_list *bl, struct map_session_data *sd) * *------------------------------------------ */ -void clif_pcinsight(struct block_list *bl, struct map_session_data *sd) +void clif_pcinsight(dumb_ptr<block_list> bl, dumb_ptr<map_session_data> sd) { - struct map_session_data *dstsd; + dumb_ptr<map_session_data> dstsd; nullpo_retv(bl); nullpo_retv(sd); @@ -2903,7 +2911,7 @@ void clif_pcinsight(struct block_list *bl, struct map_session_data *sd) switch (bl->bl_type) { case BL::PC: - dstsd = (struct map_session_data *) bl; + dstsd = bl->as_player(); if (sd != dstsd) { clif_getareachar_pc(sd, dstsd); @@ -2911,13 +2919,13 @@ void clif_pcinsight(struct block_list *bl, struct map_session_data *sd) } break; case BL::NPC: - clif_getareachar_npc(sd, (struct npc_data *) bl); + clif_getareachar_npc(sd, bl->as_npc()); break; case BL::MOB: - clif_getareachar_mob(sd, (struct mob_data *) bl); + clif_getareachar_mob(sd, bl->as_mob()); break; case BL::ITEM: - clif_getareachar_item(sd, (struct flooritem_data *) bl); + clif_getareachar_item(sd, bl->as_item()); break; } } @@ -2926,15 +2934,16 @@ void clif_pcinsight(struct block_list *bl, struct map_session_data *sd) * *------------------------------------------ */ -void clif_moboutsight(struct block_list *bl, struct mob_data *md) +void clif_moboutsight(dumb_ptr<block_list> bl, dumb_ptr<mob_data> md) { - struct map_session_data *sd; + dumb_ptr<map_session_data> sd; nullpo_retv(bl); nullpo_retv(md); - if (bl->bl_type == BL::PC && (sd = (struct map_session_data *) bl)) + if (bl->bl_type == BL::PC) { + sd = bl->as_player(); clif_clearchar_id(md->bl_id, BeingRemoveWhy::GONE, sd->fd); } } @@ -2943,15 +2952,16 @@ void clif_moboutsight(struct block_list *bl, struct mob_data *md) * *------------------------------------------ */ -void clif_mobinsight(struct block_list *bl, struct mob_data *md) +void clif_mobinsight(dumb_ptr<block_list> bl, dumb_ptr<mob_data> md) { - struct map_session_data *sd; + dumb_ptr<map_session_data> sd; nullpo_retv(bl); nullpo_retv(md); - if (bl->bl_type == BL::PC && (sd = (struct map_session_data *) bl)) + if (bl->bl_type == BL::PC) { + sd = bl->as_player(); clif_getareachar_mob(sd, md); } } @@ -2960,7 +2970,7 @@ void clif_mobinsight(struct block_list *bl, struct mob_data *md) * *------------------------------------------ */ -int clif_skillinfo(struct map_session_data *sd, SkillID skillid, int type, +int clif_skillinfo(dumb_ptr<map_session_data> sd, SkillID skillid, int type, int range) { int fd; @@ -2999,7 +3009,7 @@ int clif_skillinfo(struct map_session_data *sd, SkillID skillid, int type, * スキルリストを送信する *------------------------------------------ */ -int clif_skillinfoblock(struct map_session_data *sd) +int clif_skillinfoblock(dumb_ptr<map_session_data> sd) { int fd; int len = 4, range; @@ -3039,7 +3049,7 @@ int clif_skillinfoblock(struct map_session_data *sd) * スキル割り振り通知 *------------------------------------------ */ -int clif_skillup(struct map_session_data *sd, SkillID skill_num) +int clif_skillup(dumb_ptr<map_session_data> sd, SkillID skill_num) { int range, fd; @@ -3064,7 +3074,7 @@ int clif_skillup(struct map_session_data *sd, SkillID skill_num) * *------------------------------------------ */ -int clif_skillcastcancel(struct block_list *bl) +int clif_skillcastcancel(dumb_ptr<block_list> bl) { unsigned char buf[16]; @@ -3081,7 +3091,7 @@ int clif_skillcastcancel(struct block_list *bl) * スキル詠唱失敗 *------------------------------------------ */ -int clif_skill_fail(struct map_session_data *sd, SkillID skill_id, int type, +int clif_skill_fail(dumb_ptr<map_session_data> sd, SkillID skill_id, int type, int btype) { int fd; @@ -3110,7 +3120,7 @@ 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, +int clif_skill_damage(dumb_ptr<block_list> src, dumb_ptr<block_list> dst, tick_t tick, interval_t sdelay, interval_t ddelay, int damage, int div, SkillID skill_id, int skill_lv, int type) { @@ -3142,7 +3152,7 @@ int clif_skill_damage(struct block_list *src, struct block_list *dst, * 状態異常アイコン/メッセージ表示 *------------------------------------------ */ -int clif_status_change(struct block_list *bl, StatusChange type, int flag) +int clif_status_change(dumb_ptr<block_list> bl, StatusChange type, int flag) { unsigned char buf[16]; @@ -3177,7 +3187,7 @@ void clif_displaymessage(int fd, const_string mes) * 天の声を送信する *------------------------------------------ */ -void clif_GMmessage(struct block_list *bl, const_string mes, int flag) +void clif_GMmessage(dumb_ptr<block_list> bl, const_string mes, int flag) { unsigned char buf[mes.size() + 16]; int lp = (flag & 0x10) ? 8 : 4; @@ -3199,7 +3209,7 @@ void clif_GMmessage(struct block_list *bl, const_string mes, int flag) * 復活する *------------------------------------------ */ -int clif_resurrection(struct block_list *bl, int type) +int clif_resurrection(dumb_ptr<block_list> bl, int type) { unsigned char buf[16]; @@ -3252,7 +3262,7 @@ int clif_wis_end(int fd, int flag) // R 0098 <type>.B: 0: success to send wisper * 2 The character is already in a party. *------------------------------------------ */ -int clif_party_created(struct map_session_data *sd, int flag) +int clif_party_created(dumb_ptr<map_session_data> sd, int flag) { int fd; @@ -3273,7 +3283,7 @@ int clif_party_info(struct party *p, int fd) { unsigned char buf[1024]; int i, c; - struct map_session_data *sd = NULL; + dumb_ptr<map_session_data> sd = NULL; nullpo_ret(p); @@ -3285,7 +3295,7 @@ int clif_party_info(struct party *p, int fd) if (m->account_id > 0) { if (sd == NULL) - sd = m->sd; + sd = dumb_ptr<map_session_data>(m->sd); WBUFL(buf, 28 + c * 46) = m->account_id; memcpy(WBUFP(buf, 28 + c * 46 + 4), m->name, 24); memcpy(WBUFP(buf, 28 + c * 46 + 28), m->map, 16); @@ -3313,8 +3323,8 @@ int clif_party_info(struct party *p, int fd) * (R 00fe <sender_ID>.l <party_name>.24B) *------------------------------------------ */ -int clif_party_invite(struct map_session_data *sd, - struct map_session_data *tsd) +int clif_party_invite(dumb_ptr<map_session_data> sd, + dumb_ptr<map_session_data> tsd) { int fd; struct party *p; @@ -3348,7 +3358,7 @@ int clif_party_invite(struct map_session_data *sd, * 4 The character is in the same party. *------------------------------------------ */ -int clif_party_inviteack(struct map_session_data *sd, const char *nick, int flag) +int clif_party_inviteack(dumb_ptr<map_session_data> sd, const char *nick, int flag) { int fd; @@ -3369,7 +3379,7 @@ int clif_party_inviteack(struct map_session_data *sd, const char *nick, int flag * 0x100=一人にのみ送信 *------------------------------------------ */ -int clif_party_option(struct party *p, struct map_session_data *sd, int flag) +int clif_party_option(struct party *p, dumb_ptr<map_session_data> sd, int flag) { unsigned char buf[16]; @@ -3403,7 +3413,7 @@ int clif_party_option(struct party *p, struct map_session_data *sd, int flag) * パーティ脱退(脱退前に呼ぶこと) *------------------------------------------ */ -int clif_party_leaved(struct party *p, struct map_session_data *sd, +int clif_party_leaved(struct party *p, dumb_ptr<map_session_data> sd, int account_id, const char *name, int flag) { unsigned char buf[64]; @@ -3420,8 +3430,11 @@ int clif_party_leaved(struct party *p, struct map_session_data *sd, { if (sd == NULL) for (i = 0; i < MAX_PARTY; i++) - if ((sd = p->member[i].sd) != NULL) + { + sd = dumb_ptr<map_session_data>(p->member[i].sd); + if (sd != NULL) break; + } if (sd != NULL) clif_send(buf, clif_parse_func_table[0x105].len, sd, SendWho::PARTY); } @@ -3440,14 +3453,15 @@ int clif_party_leaved(struct party *p, struct map_session_data *sd, int clif_party_message(struct party *p, int account_id, const char *mes, int len) { // always set, but clang is not smart enough - struct map_session_data *sd = nullptr; + dumb_ptr<map_session_data> sd = nullptr; int i; nullpo_ret(p); for (i = 0; i < MAX_PARTY; i++) { - if ((sd = p->member[i].sd) != NULL) + sd = dumb_ptr<map_session_data>(p->member[i].sd); + if (sd != NULL) break; } if (sd != NULL) @@ -3466,7 +3480,7 @@ int clif_party_message(struct party *p, int account_id, const char *mes, int len * パーティ座標通知 *------------------------------------------ */ -int clif_party_xy(struct party *, struct map_session_data *sd) +int clif_party_xy(struct party *, dumb_ptr<map_session_data> sd) { unsigned char buf[16]; @@ -3486,7 +3500,7 @@ int clif_party_xy(struct party *, struct map_session_data *sd) * パーティHP通知 *------------------------------------------ */ -int clif_party_hp(struct party *, struct map_session_data *sd) +int clif_party_hp(struct party *, dumb_ptr<map_session_data> sd) { unsigned char buf[16]; @@ -3507,7 +3521,7 @@ int clif_party_hp(struct party *, struct map_session_data *sd) * 攻撃するために移動が必要 *------------------------------------------ */ -int clif_movetoattack(struct map_session_data *sd, struct block_list *bl) +int clif_movetoattack(dumb_ptr<map_session_data> sd, dumb_ptr<block_list> bl) { int fd; @@ -3530,7 +3544,7 @@ int clif_movetoattack(struct map_session_data *sd, struct block_list *bl) * MVPエフェクト *------------------------------------------ */ -int clif_mvp_effect(struct map_session_data *sd) +int clif_mvp_effect(dumb_ptr<map_session_data> sd) { unsigned char buf[16]; @@ -3546,7 +3560,7 @@ int clif_mvp_effect(struct map_session_data *sd) * エモーション *------------------------------------------ */ -void clif_emotion(struct block_list *bl, int type) +void clif_emotion(dumb_ptr<block_list> bl, int type) { unsigned char buf[8]; @@ -3559,12 +3573,12 @@ void clif_emotion(struct block_list *bl, int type) } static -void clif_emotion_towards(struct block_list *bl, - struct block_list *target, int type) +void clif_emotion_towards(dumb_ptr<block_list> bl, + dumb_ptr<block_list> target, int type) { unsigned char buf[8]; int len = clif_parse_func_table[0xc0].len; - struct map_session_data *sd = (struct map_session_data *) target; + dumb_ptr<map_session_data> sd = target->as_player(); nullpo_retv(bl); nullpo_retv(target); @@ -3584,7 +3598,7 @@ void clif_emotion_towards(struct block_list *bl, * 座る *------------------------------------------ */ -void clif_sitting(int, struct map_session_data *sd) +void clif_sitting(int, dumb_ptr<map_session_data> sd) { unsigned char buf[64]; @@ -3601,7 +3615,7 @@ void clif_sitting(int, struct map_session_data *sd) *------------------------------------------ */ static -int clif_GM_kickack(struct map_session_data *sd, int id) +int clif_GM_kickack(dumb_ptr<map_session_data> sd, int id) { int fd; @@ -3615,9 +3629,9 @@ int clif_GM_kickack(struct map_session_data *sd, int id) } static -void clif_parse_QuitGame(int fd, struct map_session_data *sd); +void clif_parse_QuitGame(int fd, dumb_ptr<map_session_data> sd); -int clif_GM_kick(struct map_session_data *sd, struct map_session_data *tsd, +int clif_GM_kick(dumb_ptr<map_session_data> sd, dumb_ptr<map_session_data> tsd, int type) { nullpo_ret(tsd); @@ -3632,7 +3646,7 @@ int clif_GM_kick(struct map_session_data *sd, struct map_session_data *tsd, } // displaying special effects (npcs, weather, etc) [Valaris] -int clif_specialeffect(struct block_list *bl, int type, int flag) +int clif_specialeffect(dumb_ptr<block_list> bl, int type, int flag) { unsigned char buf[24]; @@ -3650,7 +3664,7 @@ int clif_specialeffect(struct block_list *bl, int type, int flag) { if (!session[i]) continue; - struct map_session_data *sd = static_cast<map_session_data *>(session[i]->session_data.get()); + dumb_ptr<map_session_data> sd = dumb_ptr<map_session_data>(static_cast<map_session_data *>(session[i]->session_data.get())); if (sd && sd->state.auth && sd->bl_m == bl->bl_m) clif_specialeffect(sd, type, 1); } @@ -3673,7 +3687,7 @@ int clif_specialeffect(struct block_list *bl, int type, int flag) *------------------------------------------ */ static -void clif_parse_WantToConnection(int fd, struct map_session_data *sd) +void clif_parse_WantToConnection(int fd, dumb_ptr<map_session_data> sd) { int account_id; // account_id in the packet @@ -3695,7 +3709,7 @@ void clif_parse_WantToConnection(int fd, struct map_session_data *sd) WFIFOSET(fd, 4); // if same account already connected, we disconnect the 2 sessions - struct map_session_data *old_sd = map_id2sd(account_id); + dumb_ptr<map_session_data> old_sd = map_id2sd(account_id); if (old_sd) { clif_authfail_fd(fd, 2); // same id @@ -3705,8 +3719,8 @@ void clif_parse_WantToConnection(int fd, struct map_session_data *sd) } else { - sd = new map_session_data(); - session[fd]->session_data.reset(sd); + sd.new_(); + session[fd]->session_data.reset(sd.operator->()); sd->fd = fd; pc_setnewpc(sd, account_id, RFIFOL(fd, 6), RFIFOL(fd, 10), @@ -3727,7 +3741,7 @@ void clif_parse_WantToConnection(int fd, struct map_session_data *sd) *------------------------------------------ */ static -void clif_parse_LoadEndAck(int, struct map_session_data *sd) +void clif_parse_LoadEndAck(int, dumb_ptr<map_session_data> sd) { // struct item_data* item; int i; @@ -3828,7 +3842,7 @@ void clif_parse_LoadEndAck(int, struct map_session_data *sd) *------------------------------------------ */ static -void clif_parse_TickSend(int fd, struct map_session_data *sd) +void clif_parse_TickSend(int fd, dumb_ptr<map_session_data> sd) { nullpo_retv(sd); @@ -3842,7 +3856,7 @@ void clif_parse_TickSend(int fd, struct map_session_data *sd) *------------------------------------------ */ static -void clif_parse_WalkToXY(int fd, struct map_session_data *sd) +void clif_parse_WalkToXY(int fd, dumb_ptr<map_session_data> sd) { int x, y; @@ -3879,7 +3893,7 @@ void clif_parse_WalkToXY(int fd, struct map_session_data *sd) * *------------------------------------------ */ -void clif_parse_QuitGame(int fd, struct map_session_data *sd) +void clif_parse_QuitGame(int fd, dumb_ptr<map_session_data> sd) { tick_t tick = gettick(); @@ -3914,9 +3928,9 @@ void clif_parse_QuitGame(int fd, struct map_session_data *sd) *------------------------------------------ */ static -void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd) +void clif_parse_GetCharNameRequest(int fd, dumb_ptr<map_session_data> sd) { - struct block_list *bl; + dumb_ptr<block_list> bl; int account_id; account_id = RFIFOL(fd, 2); @@ -3931,7 +3945,7 @@ void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd) { case BL::PC: { - struct map_session_data *ssd = (struct map_session_data *) bl; + dumb_ptr<map_session_data> ssd = bl->as_player(); nullpo_retv(ssd); @@ -3982,7 +3996,7 @@ void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd) } break; case BL::NPC: - memcpy(WFIFOP(fd, 6), ((struct npc_data *) bl)->name, 24); + memcpy(WFIFOP(fd, 6), bl->as_npc()->name, 24); { char *start = (char *)WFIFOP(fd, 6); char *end = strchr(start, '#'); // [fate] elim hashed out/invisible names for the client @@ -3998,7 +4012,7 @@ void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd) break; case BL::MOB: { - struct mob_data *md = (struct mob_data *) bl; + dumb_ptr<mob_data> md = bl->as_mob(); nullpo_retv(md); @@ -4022,7 +4036,7 @@ void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd) *------------------------------------------ */ static -void clif_parse_GlobalMessage(int fd, struct map_session_data *sd) +void clif_parse_GlobalMessage(int fd, dumb_ptr<map_session_data> sd) { int msg_len = RFIFOW(fd, 2) - 4; /* Header(2) + length(2). */ size_t message_len = 0; @@ -4072,7 +4086,7 @@ void clif_parse_GlobalMessage(int fd, struct map_session_data *sd) return; } -int clif_message(struct block_list *bl, const char *msg) +int clif_message(dumb_ptr<block_list> bl, const char *msg) { unsigned short msg_len = strlen(msg) + 1; unsigned char buf[512]; @@ -4097,7 +4111,7 @@ int clif_message(struct block_list *bl, const char *msg) *------------------------------------------ */ static -void clif_parse_ChangeDir(int fd, struct map_session_data *sd) +void clif_parse_ChangeDir(int fd, dumb_ptr<map_session_data> sd) { unsigned char buf[64]; @@ -4127,7 +4141,7 @@ void clif_parse_ChangeDir(int fd, struct map_session_data *sd) *------------------------------------------ */ static -void clif_parse_Emotion(int fd, struct map_session_data *sd) +void clif_parse_Emotion(int fd, dumb_ptr<map_session_data> sd) { unsigned char buf[64]; @@ -4150,7 +4164,7 @@ void clif_parse_Emotion(int fd, struct map_session_data *sd) *------------------------------------------ */ static -void clif_parse_HowManyConnections(int fd, struct map_session_data *) +void clif_parse_HowManyConnections(int fd, dumb_ptr<map_session_data>) { WFIFOW(fd, 0) = 0xc2; WFIFOL(fd, 2) = map_getusers(); @@ -4162,7 +4176,7 @@ void clif_parse_HowManyConnections(int fd, struct map_session_data *) *------------------------------------------ */ static -void clif_parse_ActionRequest(int fd, struct map_session_data *sd) +void clif_parse_ActionRequest(int fd, dumb_ptr<map_session_data> sd) { unsigned char buf[64]; int action_type, target_id; @@ -4229,7 +4243,7 @@ void clif_parse_ActionRequest(int fd, struct map_session_data *sd) *------------------------------------------ */ static -void clif_parse_Restart(int fd, struct map_session_data *sd) +void clif_parse_Restart(int fd, dumb_ptr<map_session_data> sd) { nullpo_retv(sd); @@ -4274,12 +4288,12 @@ void clif_parse_Restart(int fd, struct map_session_data *sd) *------------------------------------------ */ static -void clif_parse_Wis(int fd, struct map_session_data *sd) +void clif_parse_Wis(int fd, dumb_ptr<map_session_data> sd) { size_t message_len = 0; char *buf = NULL; const char *message = NULL; /* The message text only. */ - struct map_session_data *dstsd = NULL; + dumb_ptr<map_session_data> dstsd = NULL; nullpo_retv(sd); @@ -4360,15 +4374,15 @@ void clif_parse_Wis(int fd, struct map_session_data *sd) *------------------------------------------ */ static -void clif_parse_TakeItem(int fd, struct map_session_data *sd) +void clif_parse_TakeItem(int fd, dumb_ptr<map_session_data> sd) { - struct flooritem_data *fitem; + dumb_ptr<flooritem_data> fitem; int map_object_id; nullpo_retv(sd); map_object_id = RFIFOL(fd, 2); - fitem = (struct flooritem_data *) map_id2bl(map_object_id); + fitem = map_id_is_item(map_object_id); if (pc_isdead(sd)) { @@ -4398,7 +4412,7 @@ void clif_parse_TakeItem(int fd, struct map_session_data *sd) *------------------------------------------ */ static -void clif_parse_DropItem(int fd, struct map_session_data *sd) +void clif_parse_DropItem(int fd, dumb_ptr<map_session_data> sd) { int item_index, item_amount; @@ -4432,7 +4446,7 @@ void clif_parse_DropItem(int fd, struct map_session_data *sd) *------------------------------------------ */ static -void clif_parse_UseItem(int fd, struct map_session_data *sd) +void clif_parse_UseItem(int fd, dumb_ptr<map_session_data> sd) { nullpo_retv(sd); @@ -4456,7 +4470,7 @@ void clif_parse_UseItem(int fd, struct map_session_data *sd) *------------------------------------------ */ static -void clif_parse_EquipItem(int fd, struct map_session_data *sd) +void clif_parse_EquipItem(int fd, dumb_ptr<map_session_data> sd) { int index; @@ -4497,7 +4511,7 @@ void clif_parse_EquipItem(int fd, struct map_session_data *sd) *------------------------------------------ */ static -void clif_parse_UnequipItem(int fd, struct map_session_data *sd) +void clif_parse_UnequipItem(int fd, dumb_ptr<map_session_data> sd) { int index; @@ -4525,7 +4539,7 @@ void clif_parse_UnequipItem(int fd, struct map_session_data *sd) *------------------------------------------ */ static -void clif_parse_NpcClicked(int fd, struct map_session_data *sd) +void clif_parse_NpcClicked(int fd, dumb_ptr<map_session_data> sd) { nullpo_retv(sd); @@ -4544,7 +4558,7 @@ void clif_parse_NpcClicked(int fd, struct map_session_data *sd) *------------------------------------------ */ static -void clif_parse_NpcBuySellSelected(int fd, struct map_session_data *sd) +void clif_parse_NpcBuySellSelected(int fd, dumb_ptr<map_session_data> sd) { npc_buysellsel(sd, RFIFOL(fd, 2), RFIFOB(fd, 6)); } @@ -4554,7 +4568,7 @@ void clif_parse_NpcBuySellSelected(int fd, struct map_session_data *sd) *------------------------------------------ */ static -void clif_parse_NpcBuyListSend(int fd, struct map_session_data *sd) +void clif_parse_NpcBuyListSend(int fd, dumb_ptr<map_session_data> sd) { int n = (RFIFOW(fd, 2) - 4) / 4; // really an array of pairs of uint16_t @@ -4572,7 +4586,7 @@ void clif_parse_NpcBuyListSend(int fd, struct map_session_data *sd) *------------------------------------------ */ static -void clif_parse_NpcSellListSend(int fd, struct map_session_data *sd) +void clif_parse_NpcSellListSend(int fd, dumb_ptr<map_session_data> sd) { int n = (RFIFOW(fd, 2) - 4) / 4; // really an array of pairs of uint16_t @@ -4590,7 +4604,7 @@ void clif_parse_NpcSellListSend(int fd, struct map_session_data *sd) *------------------------------------------ */ static -void clif_parse_TradeRequest(int, struct map_session_data *sd) +void clif_parse_TradeRequest(int, dumb_ptr<map_session_data> sd) { nullpo_retv(sd); @@ -4608,7 +4622,7 @@ void clif_parse_TradeRequest(int, struct map_session_data *sd) *------------------------------------------ */ static -void clif_parse_TradeAck(int, struct map_session_data *sd) +void clif_parse_TradeAck(int, dumb_ptr<map_session_data> sd) { nullpo_retv(sd); @@ -4620,7 +4634,7 @@ void clif_parse_TradeAck(int, struct map_session_data *sd) *------------------------------------------ */ static -void clif_parse_TradeAddItem(int, struct map_session_data *sd) +void clif_parse_TradeAddItem(int, dumb_ptr<map_session_data> sd) { nullpo_retv(sd); @@ -4632,7 +4646,7 @@ void clif_parse_TradeAddItem(int, struct map_session_data *sd) *------------------------------------------ */ static -void clif_parse_TradeOk(int, struct map_session_data *sd) +void clif_parse_TradeOk(int, dumb_ptr<map_session_data> sd) { trade_tradeok(sd); } @@ -4642,7 +4656,7 @@ void clif_parse_TradeOk(int, struct map_session_data *sd) *------------------------------------------ */ static -void clif_parse_TradeCansel(int, struct map_session_data *sd) +void clif_parse_TradeCansel(int, dumb_ptr<map_session_data> sd) { trade_tradecancel(sd); } @@ -4652,7 +4666,7 @@ void clif_parse_TradeCansel(int, struct map_session_data *sd) *------------------------------------------ */ static -void clif_parse_TradeCommit(int, struct map_session_data *sd) +void clif_parse_TradeCommit(int, dumb_ptr<map_session_data> sd) { trade_tradecommit(sd); } @@ -4662,7 +4676,7 @@ void clif_parse_TradeCommit(int, struct map_session_data *sd) *------------------------------------------ */ static -void clif_parse_StopAttack(int, struct map_session_data *sd) +void clif_parse_StopAttack(int, dumb_ptr<map_session_data> sd) { pc_stopattack(sd); } @@ -4672,7 +4686,7 @@ void clif_parse_StopAttack(int, struct map_session_data *sd) *------------------------------------------ */ static -void clif_parse_StatusUp(int fd, struct map_session_data *sd) +void clif_parse_StatusUp(int fd, dumb_ptr<map_session_data> sd) { pc_statusup(sd, SP(RFIFOW(fd, 2))); } @@ -4682,7 +4696,7 @@ void clif_parse_StatusUp(int fd, struct map_session_data *sd) *------------------------------------------ */ static -void clif_parse_SkillUp(int fd, struct map_session_data *sd) +void clif_parse_SkillUp(int fd, dumb_ptr<map_session_data> sd) { pc_skillup(sd, SkillID(RFIFOW(fd, 2))); } @@ -4692,7 +4706,7 @@ void clif_parse_SkillUp(int fd, struct map_session_data *sd) *------------------------------------------ */ static -void clif_parse_NpcSelectMenu(int fd, struct map_session_data *sd) +void clif_parse_NpcSelectMenu(int fd, dumb_ptr<map_session_data> sd) { nullpo_retv(sd); @@ -4705,7 +4719,7 @@ void clif_parse_NpcSelectMenu(int fd, struct map_session_data *sd) *------------------------------------------ */ static -void clif_parse_NpcNextClicked(int fd, struct map_session_data *sd) +void clif_parse_NpcNextClicked(int fd, dumb_ptr<map_session_data> sd) { map_scriptcont(sd, RFIFOL(fd, 2)); } @@ -4715,7 +4729,7 @@ void clif_parse_NpcNextClicked(int fd, struct map_session_data *sd) *------------------------------------------ */ static -void clif_parse_NpcAmountInput(int fd, struct map_session_data *sd) +void clif_parse_NpcAmountInput(int fd, dumb_ptr<map_session_data> sd) { nullpo_retv(sd); @@ -4730,7 +4744,7 @@ void clif_parse_NpcAmountInput(int fd, struct map_session_data *sd) *------------------------------------------ */ static -void clif_parse_NpcStringInput(int fd, struct map_session_data *sd) +void clif_parse_NpcStringInput(int fd, dumb_ptr<map_session_data> sd) { int len; nullpo_retv(sd); @@ -4762,7 +4776,7 @@ void clif_parse_NpcStringInput(int fd, struct map_session_data *sd) *------------------------------------------ */ static -void clif_parse_NpcCloseClicked(int fd, struct map_session_data *sd) +void clif_parse_NpcCloseClicked(int fd, dumb_ptr<map_session_data> sd) { map_scriptcont(sd, RFIFOL(fd, 2)); } @@ -4772,7 +4786,7 @@ void clif_parse_NpcCloseClicked(int fd, struct map_session_data *sd) *------------------------------------------ */ static -void clif_parse_MoveToKafra(int fd, struct map_session_data *sd) +void clif_parse_MoveToKafra(int fd, dumb_ptr<map_session_data> sd) { int item_index, item_amount; @@ -4794,7 +4808,7 @@ void clif_parse_MoveToKafra(int fd, struct map_session_data *sd) *------------------------------------------ */ static -void clif_parse_MoveFromKafra(int fd, struct map_session_data *sd) +void clif_parse_MoveFromKafra(int fd, dumb_ptr<map_session_data> sd) { int item_index, item_amount; @@ -4816,7 +4830,7 @@ void clif_parse_MoveFromKafra(int fd, struct map_session_data *sd) *------------------------------------------ */ static -void clif_parse_CloseKafra(int, struct map_session_data *sd) +void clif_parse_CloseKafra(int, dumb_ptr<map_session_data> sd) { nullpo_retv(sd); @@ -4832,7 +4846,7 @@ void clif_parse_CloseKafra(int, struct map_session_data *sd) *------------------------------------------ */ static -void clif_parse_CreateParty(int fd, struct map_session_data *sd) +void clif_parse_CreateParty(int fd, dumb_ptr<map_session_data> sd) { if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, SkillID::NV_PARTY) >= 2) @@ -4851,7 +4865,7 @@ void clif_parse_CreateParty(int fd, struct map_session_data *sd) *------------------------------------------ */ static -void clif_parse_PartyInvite(int fd, struct map_session_data *sd) +void clif_parse_PartyInvite(int fd, dumb_ptr<map_session_data> sd) { party_invite(sd, RFIFOL(fd, 2)); } @@ -4864,7 +4878,7 @@ void clif_parse_PartyInvite(int fd, struct map_session_data *sd) *------------------------------------------ */ static -void clif_parse_ReplyPartyInvite(int fd, struct map_session_data *sd) +void clif_parse_ReplyPartyInvite(int fd, dumb_ptr<map_session_data> sd) { if (battle_config.basic_skill_check == 0 || pc_checkskill(sd, SkillID::NV_PARTY) >= 1) @@ -4883,7 +4897,7 @@ void clif_parse_ReplyPartyInvite(int fd, struct map_session_data *sd) *------------------------------------------ */ static -void clif_parse_LeaveParty(int, struct map_session_data *sd) +void clif_parse_LeaveParty(int, dumb_ptr<map_session_data> sd) { party_leave(sd); } @@ -4893,7 +4907,7 @@ void clif_parse_LeaveParty(int, struct map_session_data *sd) *------------------------------------------ */ static -void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd) +void clif_parse_RemovePartyMember(int fd, dumb_ptr<map_session_data> sd) { party_removemember(sd, RFIFOL(fd, 2), (const char *)RFIFOP(fd, 6)); } @@ -4903,7 +4917,7 @@ void clif_parse_RemovePartyMember(int fd, struct map_session_data *sd) *------------------------------------------ */ static -void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd) +void clif_parse_PartyChangeOption(int fd, dumb_ptr<map_session_data> sd) { party_changeoption(sd, RFIFOW(fd, 2), RFIFOW(fd, 4)); } @@ -4917,7 +4931,7 @@ void clif_parse_PartyChangeOption(int fd, struct map_session_data *sd) *------------------------------------------ */ static -void clif_parse_PartyMessage(int fd, struct map_session_data *sd) +void clif_parse_PartyMessage(int fd, dumb_ptr<map_session_data> sd) { size_t message_len = 0; char *buf = NULL; @@ -4951,7 +4965,7 @@ void clif_parse_PartyMessage(int fd, struct map_session_data *sd) // 4144 wants this, but I don't like it ... static -void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd) +void clif_parse_PMIgnoreAll(int fd, dumb_ptr<map_session_data> sd) { // Rewritten by [Yor] //PRINTF("Ignore all: state: %d\n", RFIFOB(fd,2)); if (RFIFOB(fd, 2) == 0) @@ -5548,7 +5562,7 @@ func_table clif_parse_func_table[0x0220] = static int clif_check_packet_flood(int fd, int cmd) { - map_session_data *sd = static_cast<map_session_data *>(session[fd]->session_data.get()); + dumb_ptr<map_session_data> sd = dumb_ptr<map_session_data>(static_cast<map_session_data *>(session[fd]->session_data.get())); tick_t tick = gettick(); // sd will not be set if the client hasn't requested @@ -5626,7 +5640,7 @@ int clif_check_packet_flood(int fd, int cmd) } inline -void WARN_MALFORMED_MSG(struct map_session_data *sd, const char *msg) +void WARN_MALFORMED_MSG(dumb_ptr<map_session_data> sd, const char *msg) { PRINTF("clif_validate_chat(): %s (ID %d) sent a malformed message: %s.\n", sd->status.name, sd->status.account_id, msg); @@ -5644,7 +5658,7 @@ void WARN_MALFORMED_MSG(struct map_session_data *sd, const char *msg) * @return a dynamically allocated copy of the message, or NULL upon failure */ static -char *clif_validate_chat(struct map_session_data *sd, int type, +char *clif_validate_chat(dumb_ptr<map_session_data> sd, int type, const char **message, size_t *message_len) { int fd; @@ -5765,7 +5779,7 @@ static void clif_parse(int fd) { int packet_len = 0, cmd = 0; - map_session_data *sd = static_cast<map_session_data *>(session[fd]->session_data.get()); + dumb_ptr<map_session_data> sd = dumb_ptr<map_session_data>(static_cast<map_session_data *>(session[fd]->session_data.get())); if (!sd || (sd && !sd->state.auth)) { diff --git a/src/map/clif.hpp b/src/map/clif.hpp index df0a48b..5240fa1 100644 --- a/src/map/clif.hpp +++ b/src/map/clif.hpp @@ -9,7 +9,7 @@ #include "../common/timer.t.hpp" #include "battle.t.hpp" -#include "map.t.hpp" +#include "map.hpp" #include "pc.t.hpp" #include "skill.t.hpp" @@ -21,143 +21,143 @@ int clif_getport(void); int clif_countusers(void); void clif_setwaitclose(int); -int clif_authok(struct map_session_data *); +int clif_authok(dumb_ptr<map_session_data>); int clif_authfail_fd(int, int); 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(tick_t, struct block_list *, BeingRemoveWhy); +int clif_dropflooritem(dumb_ptr<flooritem_data>); +int clif_clearflooritem(dumb_ptr<flooritem_data>, int); +int clif_clearchar(dumb_ptr<block_list>, BeingRemoveWhy); // area or fd +int clif_clearchar_delay(tick_t, dumb_ptr<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 -int clif_spawn_fake_npc_for_player(struct map_session_data *sd, +int clif_spawnpc(dumb_ptr<map_session_data>); //area +int clif_spawnnpc(dumb_ptr<npc_data>); // area +int clif_spawn_fake_npc_for_player(dumb_ptr<map_session_data> sd, int fake_npc_id); -int clif_spawnmob(struct mob_data *); // area -int clif_walkok(struct map_session_data *); // self -int clif_movechar(struct map_session_data *); // area -int clif_movemob(struct mob_data *); //area -int clif_changemap(struct map_session_data *, const char *, int, int); //self -int clif_changemapserver(struct map_session_data *, const char *, int, int, struct in_addr, int); //self -int clif_fixpos(struct block_list *); // area -int clif_fixmobpos(struct mob_data *md); -int clif_fixpcpos(struct map_session_data *sd); -int clif_npcbuysell(struct map_session_data *, int); //self -int clif_buylist(struct map_session_data *, struct npc_data *); //self -int clif_selllist(struct map_session_data *); //self -int clif_scriptmes(struct map_session_data *, int, const char *); //self -int clif_scriptnext(struct map_session_data *, int); //self -int clif_scriptclose(struct map_session_data *, int); //self -int clif_scriptmenu(struct map_session_data *, int, const char *); //self -int clif_scriptinput(struct map_session_data *, int); //self -int clif_scriptinputstr(struct map_session_data *sd, int npcid); // self -int clif_cutin(struct map_session_data *, const char *, int); //self -int clif_viewpoint(struct map_session_data *, int, int, int, int, int, int); //self -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 *, +int clif_spawnmob(dumb_ptr<mob_data>); // area +int clif_walkok(dumb_ptr<map_session_data>); // self +int clif_movechar(dumb_ptr<map_session_data>); // area +int clif_movemob(dumb_ptr<mob_data>); //area +int clif_changemap(dumb_ptr<map_session_data>, const char *, int, int); //self +int clif_changemapserver(dumb_ptr<map_session_data>, const char *, int, int, struct in_addr, int); //self +int clif_fixpos(dumb_ptr<block_list>); // area +int clif_fixmobpos(dumb_ptr<mob_data> md); +int clif_fixpcpos(dumb_ptr<map_session_data> sd); +int clif_npcbuysell(dumb_ptr<map_session_data>, int); //self +int clif_buylist(dumb_ptr<map_session_data>, dumb_ptr<npc_data_shop>); //self +int clif_selllist(dumb_ptr<map_session_data>); //self +int clif_scriptmes(dumb_ptr<map_session_data>, int, const char *); //self +int clif_scriptnext(dumb_ptr<map_session_data>, int); //self +int clif_scriptclose(dumb_ptr<map_session_data>, int); //self +int clif_scriptmenu(dumb_ptr<map_session_data>, int, const char *); //self +int clif_scriptinput(dumb_ptr<map_session_data>, int); //self +int clif_scriptinputstr(dumb_ptr<map_session_data> sd, int npcid); // self +int clif_cutin(dumb_ptr<map_session_data>, const char *, int); //self +int clif_viewpoint(dumb_ptr<map_session_data>, int, int, int, int, int, int); //self +int clif_additem(dumb_ptr<map_session_data>, int, int, PickupFail); //self +int clif_delitem(dumb_ptr<map_session_data>, int, int); //self +int clif_updatestatus(dumb_ptr<map_session_data>, SP); //self +int clif_damage(dumb_ptr<block_list>, dumb_ptr<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) +int clif_takeitem(dumb_ptr<block_list> src, dumb_ptr<block_list> dst) { 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. -int clif_arrowequip(struct map_session_data *sd, int val); //self -int clif_arrow_fail(struct map_session_data *sd, int type); //self -int clif_statusupack(struct map_session_data *, SP, int, int); // self -int clif_equipitemack(struct map_session_data *, int, EPOS, int); // self -int clif_unequipitemack(struct map_session_data *, int, EPOS, int); // self -int clif_misceffect(struct block_list *, int); // area -int clif_changeoption(struct block_list *); // area -int clif_useitemack(struct map_session_data *, int, int, int); // self - -void clif_emotion(struct block_list *bl, int type); -void clif_sitting(int fd, struct map_session_data *sd); +int clif_changelook(dumb_ptr<block_list>, LOOK, int); // area +void clif_changelook_accessories(dumb_ptr<block_list> bl, dumb_ptr<map_session_data> dst); // area or target; list gloves, boots etc. +int clif_arrowequip(dumb_ptr<map_session_data> sd, int val); //self +int clif_arrow_fail(dumb_ptr<map_session_data> sd, int type); //self +int clif_statusupack(dumb_ptr<map_session_data>, SP, int, int); // self +int clif_equipitemack(dumb_ptr<map_session_data>, int, EPOS, int); // self +int clif_unequipitemack(dumb_ptr<map_session_data>, int, EPOS, int); // self +int clif_misceffect(dumb_ptr<block_list>, int); // area +int clif_changeoption(dumb_ptr<block_list>); // area +int clif_useitemack(dumb_ptr<map_session_data>, int, int, int); // self + +void clif_emotion(dumb_ptr<block_list> bl, int type); +void clif_sitting(int fd, dumb_ptr<map_session_data> sd); // trade -int clif_traderequest(struct map_session_data *sd, const char *name); -int clif_tradestart(struct map_session_data *sd, int type); -int clif_tradeadditem(struct map_session_data *sd, - struct map_session_data *tsd, int index, int amount); -int clif_tradeitemok(struct map_session_data *sd, int index, int amount, +int clif_traderequest(dumb_ptr<map_session_data> sd, const char *name); +int clif_tradestart(dumb_ptr<map_session_data> sd, int type); +int clif_tradeadditem(dumb_ptr<map_session_data> sd, + dumb_ptr<map_session_data> tsd, int index, int amount); +int clif_tradeitemok(dumb_ptr<map_session_data> sd, int index, int amount, int fail); -int clif_tradedeal_lock(struct map_session_data *sd, int fail); -int clif_tradecancelled(struct map_session_data *sd); -int clif_tradecompleted(struct map_session_data *sd, int fail); +int clif_tradedeal_lock(dumb_ptr<map_session_data> sd, int fail); +int clif_tradecancelled(dumb_ptr<map_session_data> sd); +int clif_tradecompleted(dumb_ptr<map_session_data> sd, int fail); // storage -int clif_storageitemlist(struct map_session_data *sd, struct storage *stor); -int clif_storageequiplist(struct map_session_data *sd, +int clif_storageitemlist(dumb_ptr<map_session_data> sd, struct storage *stor); +int clif_storageequiplist(dumb_ptr<map_session_data> sd, struct storage *stor); -int clif_updatestorageamount(struct map_session_data *sd, +int clif_updatestorageamount(dumb_ptr<map_session_data> sd, struct storage *stor); -int clif_storageitemadded(struct map_session_data *sd, struct storage *stor, +int clif_storageitemadded(dumb_ptr<map_session_data> sd, struct storage *stor, int index, int amount); -int clif_storageitemremoved(struct map_session_data *sd, int index, +int clif_storageitemremoved(dumb_ptr<map_session_data> sd, int index, int amount); -int clif_storageclose(struct map_session_data *sd); +int clif_storageclose(dumb_ptr<map_session_data> sd); // map_forallinmovearea callbacks -void clif_pcinsight(struct block_list *, struct map_session_data *); -void clif_pcoutsight(struct block_list *, struct map_session_data *); -void clif_mobinsight(struct block_list *, struct mob_data *); -void clif_moboutsight(struct block_list *, struct mob_data *); +void clif_pcinsight(dumb_ptr<block_list>, dumb_ptr<map_session_data>); +void clif_pcoutsight(dumb_ptr<block_list>, dumb_ptr<map_session_data>); +void clif_mobinsight(dumb_ptr<block_list>, dumb_ptr<mob_data>); +void clif_moboutsight(dumb_ptr<block_list>, dumb_ptr<mob_data>); -int clif_skillinfo(struct map_session_data *sd, SkillID skillid, int type, +int clif_skillinfo(dumb_ptr<map_session_data> sd, SkillID skillid, int type, int range); -int clif_skillinfoblock(struct map_session_data *sd); -int clif_skillup(struct map_session_data *sd, SkillID skill_num); +int clif_skillinfoblock(dumb_ptr<map_session_data> sd); +int clif_skillup(dumb_ptr<map_session_data> sd, SkillID skill_num); -int clif_skillcastcancel(struct block_list *bl); -int clif_skill_fail(struct map_session_data *sd, SkillID skill_id, int type, +int clif_skillcastcancel(dumb_ptr<block_list> bl); +int clif_skill_fail(dumb_ptr<map_session_data> sd, SkillID skill_id, int type, int btype); -int clif_skill_damage(struct block_list *src, struct block_list *dst, +int clif_skill_damage(dumb_ptr<block_list> src, dumb_ptr<block_list> dst, 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, +int clif_status_change(dumb_ptr<block_list> bl, StatusChange type, int flag); int clif_wis_message(int fd, const char *nick, const char *mes, int mes_len); int clif_wis_end(int fd, int flag); -int clif_itemlist(struct map_session_data *sd); -int clif_equiplist(struct map_session_data *sd); +int clif_itemlist(dumb_ptr<map_session_data> sd); +int clif_equiplist(dumb_ptr<map_session_data> sd); -int clif_mvp_effect(struct map_session_data *sd); +int clif_mvp_effect(dumb_ptr<map_session_data> sd); -int clif_movetoattack(struct map_session_data *sd, struct block_list *bl); +int clif_movetoattack(dumb_ptr<map_session_data> sd, dumb_ptr<block_list> bl); // party -int clif_party_created(struct map_session_data *sd, int flag); +int clif_party_created(dumb_ptr<map_session_data> sd, int flag); int clif_party_info(struct party *p, int fd); -int clif_party_invite(struct map_session_data *sd, - struct map_session_data *tsd); -int clif_party_inviteack(struct map_session_data *sd, const char *nick, int flag); -int clif_party_option(struct party *p, struct map_session_data *sd, +int clif_party_invite(dumb_ptr<map_session_data> sd, + dumb_ptr<map_session_data> tsd); +int clif_party_inviteack(dumb_ptr<map_session_data> sd, const char *nick, int flag); +int clif_party_option(struct party *p, dumb_ptr<map_session_data> sd, int flag); -int clif_party_leaved(struct party *p, struct map_session_data *sd, +int clif_party_leaved(struct party *p, dumb_ptr<map_session_data> sd, int account_id, const char *name, int flag); int clif_party_message(struct party *p, int account_id, const char *mes, int len); -int clif_party_xy(struct party *p, struct map_session_data *sd); -int clif_party_hp(struct party *p, struct map_session_data *sd); +int clif_party_xy(struct party *p, dumb_ptr<map_session_data> sd); +int clif_party_hp(struct party *p, dumb_ptr<map_session_data> sd); // atcommand void clif_displaymessage(int fd, const_string mes); -void clif_GMmessage(struct block_list *bl, const_string mes, int flag); -int clif_resurrection(struct block_list *bl, int type); +void clif_GMmessage(dumb_ptr<block_list> bl, const_string mes, int flag); +int clif_resurrection(dumb_ptr<block_list> bl, int type); -int clif_specialeffect(struct block_list *bl, int type, int flag); // special effects [Valaris] -int clif_message(struct block_list *bl, const char *msg); // messages (from mobs/npcs) [Valaris] +int clif_specialeffect(dumb_ptr<block_list> bl, int type, int flag); // special effects [Valaris] +int clif_message(dumb_ptr<block_list> bl, const char *msg); // messages (from mobs/npcs) [Valaris] -int clif_GM_kick(struct map_session_data *sd, struct map_session_data *tsd, +int clif_GM_kick(dumb_ptr<map_session_data> sd, dumb_ptr<map_session_data> tsd, int type); -int clif_foreachclient(std::function<void(struct map_session_data *)>); +int clif_foreachclient(std::function<void(dumb_ptr<map_session_data>)>); int do_init_clif (void); diff --git a/src/map/intif.cpp b/src/map/intif.cpp index c5d3c90..53ff80e 100644 --- a/src/map/intif.cpp +++ b/src/map/intif.cpp @@ -47,7 +47,7 @@ void intif_GMmessage(const_string mes, int flag) } // The transmission of Wisp/Page to inter-server (player not found on this server) -int intif_wis_message(struct map_session_data *sd, const char *nick, const char *mes, +int intif_wis_message(dumb_ptr<map_session_data> sd, const char *nick, const char *mes, int mes_len) { nullpo_ret(sd); @@ -100,7 +100,7 @@ int intif_wis_message_to_gm(const char *Wisp_name, int min_gm_level, const char } // アカウント変数送信 -int intif_saveaccountreg(struct map_session_data *sd) +int intif_saveaccountreg(dumb_ptr<map_session_data> sd) { int j, p; @@ -119,7 +119,7 @@ int intif_saveaccountreg(struct map_session_data *sd) } // アカウント変数要求 -int intif_request_accountreg(struct map_session_data *sd) +int intif_request_accountreg(dumb_ptr<map_session_data> sd) { nullpo_ret(sd); @@ -151,7 +151,7 @@ int intif_send_storage(struct storage *stor) } // パーティ作成要求 -int intif_create_party(struct map_session_data *sd, const char *name) +int intif_create_party(dumb_ptr<map_session_data> sd, const char *name) { nullpo_ret(sd); @@ -181,7 +181,7 @@ int intif_request_partyinfo(int party_id) // パーティ追加要求 int intif_party_addmember(int party_id, int account_id) { - struct map_session_data *sd; + dumb_ptr<map_session_data> sd; sd = map_id2sd(account_id); // if(battle_config.etc_log) // PRINTF("intif: party add member %d %d\n",party_id,account_id); @@ -223,7 +223,7 @@ int intif_party_leave(int party_id, int account_id) } // パーティ移動要求 -int intif_party_changemap(struct map_session_data *sd, int online) +int intif_party_changemap(dumb_ptr<map_session_data> sd, int online) { if (sd != NULL) { @@ -272,7 +272,7 @@ int intif_party_checkconflict(int party_id, int account_id, const char *nick) static int intif_parse_WisMessage(int fd) { // rewritten by [Yor] - struct map_session_data *sd; + dumb_ptr<map_session_data> sd; int i; if (battle_config.etc_log) @@ -316,7 +316,7 @@ int intif_parse_WisMessage(int fd) static int intif_parse_WisEnd(int fd) { - struct map_session_data *sd; + dumb_ptr<map_session_data> sd; if (battle_config.etc_log) // flag: 0: success to send wisper, 1: target character is not loged in?, 2: ignored by target @@ -354,7 +354,7 @@ int mapif_parse_WisToGM(int fd) { if (!session[i]) continue; - map_session_data *pl_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + dumb_ptr<map_session_data> pl_sd = dumb_ptr<map_session_data>(static_cast<map_session_data *>(session[i]->session_data.get())); if (pl_sd && pl_sd->state.auth) if (pc_isGM(pl_sd) >= min_gm_level) clif_wis_message(i, Wisp_name, message, @@ -372,7 +372,7 @@ static int intif_parse_AccountReg(int fd) { int j, p; - struct map_session_data *sd; + dumb_ptr<map_session_data> sd; if ((sd = map_id2sd(RFIFOL(fd, 4))) == NULL) return 1; @@ -393,7 +393,7 @@ static int intif_parse_LoadStorage(int fd) { struct storage *stor; - struct map_session_data *sd; + dumb_ptr<map_session_data> sd; sd = map_id2sd(RFIFOL(fd, 4)); if (sd == NULL) diff --git a/src/map/intif.hpp b/src/map/intif.hpp index 25f69e3..766af59 100644 --- a/src/map/intif.hpp +++ b/src/map/intif.hpp @@ -3,28 +3,30 @@ #include "../common/const_array.hpp" +#include "map.hpp" + int intif_parse(int fd); void intif_GMmessage(const_string mes, int flag); -int intif_wis_message(struct map_session_data *sd, const char *nick, const char *mes, +int intif_wis_message(dumb_ptr<map_session_data> sd, const char *nick, const char *mes, int mes_len); int intif_wis_message_to_gm(const char *Wisp_name, int min_gm_level, const char *mes, int mes_len); -int intif_saveaccountreg(struct map_session_data *sd); -int intif_request_accountreg(struct map_session_data *sd); +int intif_saveaccountreg(dumb_ptr<map_session_data> sd); +int intif_request_accountreg(dumb_ptr<map_session_data> sd); int intif_request_storage(int account_id); int intif_send_storage(struct storage *stor); -int intif_create_party(struct map_session_data *sd, const char *name); +int intif_create_party(dumb_ptr<map_session_data> sd, const char *name); int intif_request_partyinfo(int party_id); int intif_party_addmember(int party_id, int account_id); int intif_party_changeoption(int party_id, int account_id, int exp, int item); int intif_party_leave(int party_id, int accound_id); -int intif_party_changemap(struct map_session_data *sd, int online); +int intif_party_changemap(dumb_ptr<map_session_data> sd, int online); int intif_party_message(int party_id, int account_id, const char *mes, int len); int intif_party_checkconflict(int party_id, int account_id, const char *nick); diff --git a/src/map/magic-expr-eval.hpp b/src/map/magic-expr-eval.hpp index d61d397..bc5ce6e 100644 --- a/src/map/magic-expr-eval.hpp +++ b/src/map/magic-expr-eval.hpp @@ -16,7 +16,7 @@ void magic_area_rect(int *m, int *x, int *y, int *width, int *height, #define ARGINT(x) args[x].v.v_int #define ARGDIR(x) args[x].v.v_dir #define ARGSTR(x) args[x].v.v_string -#define ARGENTITY(x) args[x].v.v_entity +#define ARGENTITY(x) dumb_ptr<block_list>(args[x].v.v_entity) #define ARGLOCATION(x) args[x].v.v_location #define ARGAREA(x) args[x].v.v_area #define ARGSPELL(x) args[x].v.v_spell @@ -34,9 +34,9 @@ void magic_area_rect(int *m, int *x, int *y, int *width, int *height, #define ARG_TYPE(x) args[x].ty #define ENTITY_TYPE(x) ARGENTITY(x)->bl_type -#define ARGPC(x) ((struct map_session_data *)ARGENTITY(x)) -#define ARGNPC(x) ((struct map_session_data *)ARGENTITY(x)) -#define ARGMOB(x) ((struct map_session_data *)ARGENTITY(x)) +#define ARGPC(x) (ARGENTITY(x)->as_player()) +#define ARGNPC(x) (ARGENTITY(x)->as_npc()) +#define ARGMOB(x) (ARGENTITY(x)->as_mob()) #define ARG_MAY_BE_AREA(x) (ARG_TYPE(x) == TYPE::AREA || ARG_TYPE(x) == TYPE::LOCATION) diff --git a/src/map/magic-expr.cpp b/src/map/magic-expr.cpp index f25bf87..c0eaf9f 100644 --- a/src/map/magic-expr.cpp +++ b/src/map/magic-expr.cpp @@ -2,6 +2,7 @@ #include "magic-expr.hpp" #include "magic-interpreter-aux.hpp" +#include <cassert> #include <cmath> #include "../common/cxxstdio.hpp" @@ -86,21 +87,21 @@ void magic_clear_var(val_t *v) } static -const char *show_entity(entity_t *entity) +const char *show_entity(dumb_ptr<block_list> entity) { switch (entity->bl_type) { case BL::PC: - return ((struct map_session_data *) entity)->status.name; + return entity->as_player()->status.name; case BL::NPC: - return ((struct npc_data *) entity)->name; + return entity->as_npc()->name; case BL::MOB: - return ((struct mob_data *) entity)->name; + return entity->as_mob()->name; case BL::ITEM: + assert (0 && "There is no way this code did what it was supposed to do!"); /* Sorry about this one... */ - return ((struct item_data - *) (&((struct flooritem_data *) entity)-> - item_data))->name; + // WTF? item_data is a struct item, not a struct item_data + // return ((struct item_data *) (&entity->as_item()->item_data))->name; case BL::SPELL: return "%invocation(ERROR:this-should-not-be-an-entity)"; default: @@ -138,7 +139,7 @@ void stringify(val_t *v, int within_op) break; case TYPE::ENTITY: - buf = show_entity(v->v.v_entity); + buf = show_entity(dumb_ptr<block_list>(v->v.v_entity)); break; case TYPE::LOCATION: @@ -159,10 +160,10 @@ void stringify(val_t *v, int within_op) case TYPE::INVOCATION: { - invocation_t *invocation = within_op - ? v->v.v_invocation - : (invocation_t *) map_id2bl(v->v.v_int); - buf = invocation->spell->name; + dumb_ptr<invocation> invocation_ = within_op + ? dumb_ptr<invocation>(v->v.v_invocation) + : map_id2bl(v->v.v_int)->as_spell(); + buf = invocation_->spell->name; } break; @@ -239,7 +240,8 @@ void make_spell(val_t *v) { if (v->ty == TYPE::INVOCATION) { - invocation_t *invoc = v->v.v_invocation; //(invocation_t *) map_id2bl(v->v.v_int); + dumb_ptr<invocation> invoc = dumb_ptr<invocation>(v->v.v_invocation); + //invoc = (dumb_ptr<invocation>) map_id2bl(v->v.v_int); if (!invoc) v->ty = TYPE::FAIL; else @@ -670,12 +672,12 @@ int fun_mob_id(env_t *, int, val_t *result, val_t *args) { if (ENTITY_TYPE(0) != BL::MOB) return 1; - RESULTINT = ((struct mob_data *)(ARGENTITY(0)))->mob_class; + RESULTINT = ARGMOB(0)->mob_class; return 0; } inline -void COPY_LOCATION(entity_t& dest, location_t& src) +void COPY_LOCATION(block_list& dest, location_t& src) { dest.bl_x = src.x; dest.bl_y = src.y; @@ -683,7 +685,7 @@ void COPY_LOCATION(entity_t& dest, location_t& src) } inline -void COPY_LOCATION(location_t& dest, entity_t& src) +void COPY_LOCATION(location_t& dest, block_list& src) { dest.x = src.bl_x; dest.y = src.bl_y; @@ -768,7 +770,7 @@ magic_find_item(val_t *args, int index, struct item *item, int *stackable) static int fun_count_item(env_t *, int, val_t *result, val_t *args) { - character_t *chr = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : NULL; + dumb_ptr<map_session_data> chr = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : NULL; int stackable; struct item item; @@ -784,7 +786,7 @@ int fun_count_item(env_t *, int, val_t *result, val_t *args) static int fun_is_equipped(env_t *, int, val_t *result, val_t *args) { - character_t *chr = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : NULL; + dumb_ptr<map_session_data> chr = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : NULL; int stackable; struct item item; bool retval = false; @@ -834,8 +836,7 @@ int fun_partner(env_t *, int, val_t *result, val_t *args) if (ENTITY_TYPE(0) == BL::PC && ARGPC(0)->status.partner_id) { RESULTENTITY = - (entity_t *) - map_nick2sd(map_charid2nick(ARGPC(0)->status.partner_id)); + map_nick2sd(map_charid2nick(ARGPC(0)->status.partner_id)).operator->(); return 0; } else @@ -871,14 +872,14 @@ int fun_failed(env_t *, int, val_t *result, val_t *args) static int fun_npc(env_t *, int, val_t *result, val_t *args) { - RESULTENTITY = (entity_t *) npc_name2id(ARGSTR(0)); + RESULTENTITY = npc_name2id(ARGSTR(0)).operator->(); return RESULTENTITY == NULL; } static int fun_pc(env_t *, int, val_t *result, val_t *args) { - RESULTENTITY = (entity_t *) map_nick2sd(ARGSTR(0)); + RESULTENTITY = map_nick2sd(ARGSTR(0)).operator->(); return RESULTENTITY == NULL; } @@ -930,12 +931,12 @@ int fun_anchor(env_t *env, int, val_t *result, val_t *args) static int fun_line_of_sight(env_t *, int, val_t *result, val_t *args) { - entity_t e1, e2; + block_list e1, e2; COPY_LOCATION(e1, ARGLOCATION(0)); COPY_LOCATION(e2, ARGLOCATION(1)); - RESULTINT = battle_check_range(&e1, &e2, 0); + RESULTINT = battle_check_range(dumb_ptr<block_list>(&e1), dumb_ptr<block_list>(&e2), 0); return 0; } @@ -992,13 +993,13 @@ int fun_pick_location(env_t *, int, val_t *result, val_t *args) static int fun_read_script_int(env_t *, int, val_t *result, val_t *args) { - entity_t *subject_p = ARGENTITY(0); + dumb_ptr<block_list> subject_p = ARGENTITY(0); char *var_name = ARGSTR(1); if (subject_p->bl_type != BL::PC) return 1; - RESULTINT = pc_readglobalreg((character_t *) subject_p, var_name); + RESULTINT = pc_readglobalreg(subject_p->as_player(), var_name); return 0; } @@ -1024,7 +1025,7 @@ int fun_running_status_update(env_t *, int, val_t *result, val_t *args) if (ENTITY_TYPE(0) != BL::PC && ENTITY_TYPE(0) != BL::MOB) return 1; - StatusChange sc = StatusChange(ARGINT(1)); + StatusChange sc = static_cast<StatusChange>(ARGINT(1)); RESULTINT = bool(battle_get_sc_data(ARGENTITY(0))[sc].timer); return 0; } @@ -1032,9 +1033,7 @@ int fun_running_status_update(env_t *, int, val_t *result, val_t *args) static int fun_status_option(env_t *, int, val_t *result, val_t *args) { - RESULTINT = - (bool(((struct map_session_data *) ARGENTITY(0))-> - status.option & Option(ARGINT(0)))); + RESULTINT = (bool((ARGPC(0))->status.option & static_cast<Option>(ARGINT(0)))); return 0; } @@ -1206,7 +1205,7 @@ int fun_dir_towards(env_t *, int, val_t *result, val_t *args) static int fun_extract_healer_xp(env_t *, int, val_t *result, val_t *args) { - character_t *sd = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : NULL; + dumb_ptr<map_session_data> sd = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : NULL; if (!sd) RESULTINT = 0; @@ -1515,13 +1514,13 @@ int magic_signature_check(const char *opname, const char *funname, const char *s if (ty == TYPE::ENTITY) { /* Dereference entities in preparation for calling function */ - arg->v.v_entity = map_id2bl(arg->v.v_int); + arg->v.v_entity = map_id2bl(arg->v.v_int).operator->(); if (!arg->v.v_entity) ty = arg->ty = TYPE::FAIL; } else if (ty == TYPE::INVOCATION) { - arg->v.v_invocation = (invocation_t *) map_id2bl(arg->v.v_int); + arg->v.v_invocation = map_id2bl(arg->v.v_int)->as_spell().operator->(); if (!arg->v.v_entity) ty = arg->ty = TYPE::FAIL; } @@ -1659,7 +1658,7 @@ void magic_eval(env_t *env, val_t *dest, expr_t *expr) if (v.ty == TYPE::INVOCATION) { - invocation_t *t = (invocation_t *) map_id2bl(v.v.v_int); + dumb_ptr<invocation> t = map_id2bl(v.v.v_int)->as_spell(); if (!t) dest->ty = TYPE::UNDEF; diff --git a/src/map/magic-interpreter-base.cpp b/src/map/magic-interpreter-base.cpp index f9832b5..775e7e4 100644 --- a/src/map/magic-interpreter-base.cpp +++ b/src/map/magic-interpreter-base.cpp @@ -29,14 +29,14 @@ static void set_string SETTER(char *, TYPE::STRING, v_string) static -void set_entity(val_t *v, entity_t *e) +void set_entity(val_t *v, dumb_ptr<block_list> e) { v->ty = TYPE::ENTITY; v->v.v_int = e->bl_id; } static -void set_invocation(val_t *v, invocation_t *i) +void set_invocation(val_t *v, dumb_ptr<invocation> i) { v->ty = TYPE::INVOCATION; v->v.v_int = i->bl_id; @@ -192,7 +192,7 @@ void magic_free_env(env_t *env) } env_t *spell_create_env(magic_conf_t *conf, spell_t *spell, - character_t *caster, int spellpower, char *param) + dumb_ptr<map_session_data> caster, int spellpower, char *param) { env_t *env = alloc_env(conf); @@ -205,7 +205,7 @@ env_t *spell_create_env(magic_conf_t *conf, spell_t *spell, case SPELLARG::PC: { - character_t *subject = map_nick2sd(param); + dumb_ptr<map_session_data> subject = map_nick2sd(param); if (!subject) subject = caster; set_env_entity(spell->arg, subject); @@ -287,7 +287,7 @@ typedef struct spellguard_check } spellguard_check_t; static -int check_prerequisites(character_t *caster, component_t *component) +int check_prerequisites(dumb_ptr<map_session_data> caster, component_t *component) { while (component) { @@ -302,7 +302,7 @@ int check_prerequisites(character_t *caster, component_t *component) } static -void consume_components(character_t *caster, component_t *component) +void consume_components(dumb_ptr<map_session_data> caster, component_t *component) { while (component) { @@ -312,7 +312,7 @@ void consume_components(character_t *caster, component_t *component) } static -int spellguard_can_satisfy(spellguard_check_t *check, character_t *caster, +int spellguard_can_satisfy(spellguard_check_t *check, dumb_ptr<map_session_data> caster, env_t *env, int *near_miss) { tick_t tick = gettick(); @@ -345,7 +345,7 @@ int spellguard_can_satisfy(spellguard_check_t *check, character_t *caster, static effect_set_t *spellguard_check_sub(spellguard_check_t *check, spellguard_t *guard, - character_t *caster, env_t *env, + dumb_ptr<map_session_data> caster, env_t *env, int *near_miss) { if (guard == NULL) @@ -414,7 +414,7 @@ effect_set_t *spellguard_check_sub(spellguard_check_t *check, static effect_set_t *check_spellguard(spellguard_t *guard, - character_t *caster, env_t *env, + dumb_ptr<map_session_data> caster, env_t *env, int *near_miss) { spellguard_check_t check; @@ -436,7 +436,7 @@ effect_set_t *check_spellguard(spellguard_t *guard, /* Public API */ /* -------------------------------------------------------------------------------- */ -effect_set_t *spell_trigger(spell_t *spell, character_t *caster, +effect_set_t *spell_trigger(spell_t *spell, dumb_ptr<map_session_data> caster, env_t *env, int *near_miss) { int i; @@ -453,7 +453,7 @@ effect_set_t *spell_trigger(spell_t *spell, character_t *caster, } static -void spell_set_location(invocation_t *invocation, entity_t *entity) +void spell_set_location(dumb_ptr<invocation> invocation, dumb_ptr<block_list> entity) { magic_clear_var(&invocation->env->vars[VAR_LOCATION]); invocation->env->vars[VAR_LOCATION].ty = TYPE::LOCATION; @@ -462,25 +462,26 @@ void spell_set_location(invocation_t *invocation, entity_t *entity) invocation->env->vars[VAR_LOCATION].v.v_location.y = entity->bl_y; } -void spell_update_location(invocation_t *invocation) +void spell_update_location(dumb_ptr<invocation> invocation) { if (bool(invocation->spell->flags & SPELL_FLAG::LOCAL)) return; else { - character_t *owner = (character_t *) map_id2bl(invocation->subject); - if (!owner) + dumb_ptr<block_list> owner_bl = map_id2bl(invocation->subject); + if (!owner_bl) return; + dumb_ptr<map_session_data> owner = owner_bl->as_player(); - spell_set_location(invocation, (entity_t *) owner); + spell_set_location(invocation, owner); } } -invocation_t *spell_instantiate(effect_set_t *effect_set, env_t *env) +dumb_ptr<invocation> spell_instantiate(effect_set_t *effect_set, env_t *env) { - invocation_t *retval; - CREATE(retval, invocation_t, 1); - entity_t *caster; + dumb_ptr<invocation> retval; + retval.new_(); + dumb_ptr<block_list> caster; retval->env = env; @@ -504,29 +505,39 @@ invocation_t *spell_instantiate(effect_set_t *effect_set, env_t *env) return retval; } -invocation_t *spell_clone_effect(invocation_t *base) +dumb_ptr<invocation> spell_clone_effect(dumb_ptr<invocation> base) { - invocation_t *retval = (invocation_t *) calloc(1, sizeof(invocation_t)); - env_t *env; + dumb_ptr<invocation> retval; + retval.new_(); - memcpy(retval, base, sizeof(invocation_t)); + // block_list in general is not copyable + // since this is the only call site, it is expanded here + //*retval = *base; - retval->env = clone_env(retval->env); - env = retval->env; - retval->current_effect = retval->trigger_effect; retval->next_invocation = NULL; - retval->end_effect = NULL; - retval->script_pos = 0; - retval->stack_size = 0; - // retval->timer = 0; + retval->flags = INVOCATION_FLAG::ZERO; + env_t *env = retval->env = clone_env(base->env); + retval->spell = base->spell; + retval->caster = base->caster; retval->subject = 0; + // retval->timer = 0; + retval->stack_size = 0; + // retval->stack = undef; + retval->script_pos = 0; + // huh? + retval->current_effect = base->trigger_effect; + retval->trigger_effect = base->trigger_effect; + retval->end_effect = NULL; retval->status_change_refs_nr = 0; retval->status_change_refs = NULL; - retval->flags = INVOCATION_FLAG::ZERO; retval->bl_id = 0; retval->bl_prev = NULL; retval->bl_next = NULL; + retval->bl_m = base->bl_m; + retval->bl_x = base->bl_x; + retval->bl_y = base->bl_y; + retval->bl_type = base->bl_type; retval->bl_id = map_addobject(retval); set_env_invocation(VAR_INVOCATION, retval); @@ -534,7 +545,7 @@ invocation_t *spell_clone_effect(invocation_t *base) return retval; } -void spell_bind(character_t *subject, invocation_t *invocation) +void spell_bind(dumb_ptr<map_session_data> subject, dumb_ptr<invocation> invocation) { /* Only bind nonlocal spells */ @@ -557,22 +568,22 @@ void spell_bind(character_t *subject, invocation_t *invocation) invocation->subject = subject->bl_id; } - spell_set_location(invocation, (entity_t *) subject); + spell_set_location(invocation, (dumb_ptr<block_list> ) subject); } -int spell_unbind(character_t *subject, invocation_t *invocation) +int spell_unbind(dumb_ptr<map_session_data> subject, dumb_ptr<invocation> invocation_) { - invocation_t **seeker = &subject->active_spells; + dumb_ptr<invocation> *seeker = &subject->active_spells; while (*seeker) { - if (*seeker == invocation) + if (*seeker == invocation_) { - *seeker = invocation->next_invocation; + *seeker = invocation_->next_invocation; - invocation->flags &= ~INVOCATION_FLAG::BOUND; - invocation->next_invocation = NULL; - invocation->subject = 0; + invocation_->flags &= ~INVOCATION_FLAG::BOUND; + invocation_->next_invocation = NULL; + invocation_->subject = 0; return 0; } diff --git a/src/map/magic-interpreter.hpp b/src/map/magic-interpreter.hpp index 5d3d389..432245d 100644 --- a/src/map/magic-interpreter.hpp +++ b/src/map/magic-interpreter.hpp @@ -50,10 +50,12 @@ typedef struct val int v_int; DIR v_dir; char *v_string; - entity_t *v_entity; /* Used ONLY during operation/function invocation; otherwise we use v_int */ + // can't be dumb_ptr<block_list> + block_list *v_entity; /* Used ONLY during operation/function invocation; otherwise we use v_int */ area_t *v_area; location_t v_location; - struct invocation *v_invocation; /* Used ONLY during operation/function invocation; otherwise we use v_int */ + // can't be dumb_ptr<invocation> + invocation *v_invocation; /* Used ONLY during operation/function invocation; otherwise we use v_int */ struct spell *v_spell; } v; TYPE ty; @@ -308,10 +310,9 @@ typedef struct status_change_ref int bl_id; } status_change_ref_t; -typedef struct invocation invocation_t; struct invocation : block_list { - struct invocation *next_invocation; /* used for spells directly associated with a caster: they form a singly-linked list */ + dumb_ptr<invocation> next_invocation; /* used for spells directly associated with a caster: they form a singly-linked list */ INVOCATION_FLAG flags; env_t *env; @@ -335,6 +336,9 @@ struct invocation : block_list }; +inline dumb_ptr<invocation> block_list::as_spell() { return dumb_ptr<invocation>(static_cast<invocation *>(this)); } +inline dumb_ptr<invocation> block_list::is_spell() { return bl_type == BL::SPELL ? as_spell() : nullptr; } + extern magic_conf_t magic_conf; /* Global magic conf */ extern env_t magic_default_env; /* Fake default environment */ @@ -349,30 +353,30 @@ teleport_anchor_t *magic_find_anchor(char *name); * The parameter `param' must have been dynamically allocated; ownership is transferred to the resultant env_t. */ env_t *spell_create_env(magic_conf_t *conf, spell_t *spell, - character_t *caster, int spellpower, char *param); + dumb_ptr<map_session_data> caster, int spellpower, char *param); void magic_free_env(env_t *env); /** * near_miss is set to nonzero iff the spell only failed due to ephemereal issues (spell delay in effect, out of mana, out of components) */ -effect_set_t *spell_trigger(spell_t *spell, character_t *caster, +effect_set_t *spell_trigger(spell_t *spell, dumb_ptr<map_session_data> caster, env_t *env, int *near_miss); -invocation_t *spell_instantiate(effect_set_t *effect, env_t *env); +dumb_ptr<invocation> spell_instantiate(effect_set_t *effect, env_t *env); /** * Bind a spell to a subject (this is a no-op for `local' spells). */ -void spell_bind(character_t *subject, invocation_t *invocation); +void spell_bind(dumb_ptr<map_session_data> subject, dumb_ptr<invocation> invocation); // 1 on failure -int spell_unbind(character_t *subject, invocation_t *invocation); +int spell_unbind(dumb_ptr<map_session_data> subject, dumb_ptr<invocation> invocation); /** * Clones a spell to run the at_effect field */ -invocation_t *spell_clone_effect(invocation_t *source); +dumb_ptr<invocation> spell_clone_effect(dumb_ptr<invocation> source); spell_t *magic_find_spell(char *invocation); @@ -393,6 +397,6 @@ typedef struct // must be called after itemdb initialisation int magic_init(const char *); -void spell_update_location(invocation_t *invocation); +void spell_update_location(dumb_ptr<invocation> invocation); #endif // MAGIC_INTERPRETER_HPP diff --git a/src/map/magic-stmt.cpp b/src/map/magic-stmt.cpp index 3b56cbd..d7944f1 100644 --- a/src/map/magic-stmt.cpp +++ b/src/map/magic-stmt.cpp @@ -82,55 +82,55 @@ void clear_activation_record(cont_activation_record_t *ar) static void invocation_timer_callback(TimerData *, tick_t, int id) { - invocation_t *invocation = (invocation_t *) map_id2bl(id); + dumb_ptr<invocation> invocation = map_id_as_spell(id); - assert (invocation != NULL); + assert (invocation); { spell_execute(invocation); } } static -void clear_stack(invocation_t *invocation) +void clear_stack(dumb_ptr<invocation> invocation_) { int i; - for (i = 0; i < invocation->stack_size; i++) - clear_activation_record(&invocation->stack[i]); + for (i = 0; i < invocation_->stack_size; i++) + clear_activation_record(&invocation_->stack[i]); - invocation->stack_size = 0; + invocation_->stack_size = 0; } -void spell_free_invocation(invocation_t *invocation) +void spell_free_invocation(dumb_ptr<invocation> invocation_) { - if (invocation->status_change_refs) + if (invocation_->status_change_refs) { - free(invocation->status_change_refs); + free(invocation_->status_change_refs); /* The following cleanup shouldn't be necessary, but I've added it to help tracking a certain bug */ - invocation->status_change_refs = NULL; - invocation->status_change_refs_nr = 0; + invocation_->status_change_refs = NULL; + invocation_->status_change_refs_nr = 0; } - if (bool(invocation->flags & INVOCATION_FLAG::BOUND)) + if (bool(invocation_->flags & INVOCATION_FLAG::BOUND)) { - entity_t *e = map_id2bl(invocation->subject); - if (e && e->bl_type == BL::PC) - spell_unbind((character_t *) e, invocation); + dumb_ptr<map_session_data> e = map_id_is_player(invocation_->subject); + if (e) + spell_unbind(e, invocation_); } - clear_stack(invocation); + clear_stack(invocation_); - invocation->timer.cancel(); + invocation_->timer.cancel(); - magic_free_env(invocation->env); + magic_free_env(invocation_->env); - map_delblock(invocation); - map_delobject(invocation->bl_id, BL::SPELL); // also frees the object -// free(invocation); + map_delblock(invocation_); + map_delobject(invocation_->bl_id, BL::SPELL); // also frees the object +// free(invocation_); } static -void char_set_weapon_icon(character_t *subject, int count, +void char_set_weapon_icon(dumb_ptr<map_session_data> subject, int count, StatusChange icon, int look) { const StatusChange old_icon = subject->attack_spell_icon_override; @@ -157,7 +157,7 @@ void char_set_weapon_icon(character_t *subject, int count, } static -void char_set_attack_info(character_t *subject, interval_t speed, int range) +void char_set_attack_info(dumb_ptr<map_session_data> subject, interval_t speed, int range) { subject->attack_spell_delay = speed; subject->attack_spell_range = range; @@ -176,7 +176,7 @@ void char_set_attack_info(character_t *subject, interval_t speed, int range) } } -void magic_stop_completely(character_t *c) +void magic_stop_completely(dumb_ptr<map_session_data> c) { // Zap all status change references to spells for (StatusChange i : erange(StatusChange(), StatusChange::MAX_STATUSCHANGE)) @@ -187,8 +187,7 @@ void magic_stop_completely(character_t *c) if (c->attack_spell_override) { - invocation_t *attack_spell = - (invocation_t *) map_id2bl(c->attack_spell_override); + dumb_ptr<invocation> attack_spell = map_id_as_spell(c->attack_spell_override); if (attack_spell) spell_free_invocation(attack_spell); c->attack_spell_override = 0; @@ -199,7 +198,7 @@ void magic_stop_completely(character_t *c) /* Spell execution has finished normally or we have been notified by a finished skill timer */ static -void try_to_finish_invocation(invocation_t *invocation) +void try_to_finish_invocation(dumb_ptr<invocation> invocation) { if (invocation->status_change_refs_nr == 0 && !invocation->current_effect) { @@ -218,41 +217,41 @@ void try_to_finish_invocation(invocation_t *invocation) static int trigger_spell(int subject, int spell) { - invocation_t *invocation = (invocation_t *) map_id2bl(spell); + dumb_ptr<invocation> invocation_ = map_id_as_spell(spell); - if (!invocation) + if (!invocation_) return 0; - invocation = spell_clone_effect(invocation); + invocation_ = spell_clone_effect(invocation_); - spell_bind((character_t *) map_id2bl(subject), invocation); - magic_clear_var(&invocation->env->vars[VAR_CASTER]); - invocation->env->vars[VAR_CASTER].ty = TYPE::ENTITY; - invocation->env->vars[VAR_CASTER].v.v_int = subject; + spell_bind(map_id_as_player(subject), invocation_); + magic_clear_var(&invocation_->env->vars[VAR_CASTER]); + invocation_->env->vars[VAR_CASTER].ty = TYPE::ENTITY; + invocation_->env->vars[VAR_CASTER].v.v_int = subject; - return invocation->bl_id; + return invocation_->bl_id; } static -void entity_warp(entity_t *target, int destm, int destx, int desty); +void entity_warp(dumb_ptr<block_list> target, int destm, int destx, int desty); static -void char_update(character_t *character) +void char_update(dumb_ptr<map_session_data> character) { - entity_warp((entity_t *) character, character->bl_m, character->bl_x, + entity_warp((dumb_ptr<block_list> ) character, character->bl_m, character->bl_x, character->bl_y); } static void timer_callback_effect(TimerData *, tick_t, int id, int data) { - entity_t *target = map_id2bl(id); + dumb_ptr<block_list> target = map_id2bl(id); if (target) clif_misceffect(target, data); } static -void entity_effect(entity_t *entity, int effect_nr, interval_t delay) +void entity_effect(dumb_ptr<block_list> entity, int effect_nr, interval_t delay) { Timer(gettick() + delay, std::bind(&timer_callback_effect, ph::_1, ph::_2, @@ -260,7 +259,7 @@ void entity_effect(entity_t *entity, int effect_nr, interval_t delay) ).detach(); } -void magic_unshroud(character_t *other_char) +void magic_unshroud(dumb_ptr<map_session_data> other_char) { other_char->state.shroud_active = 0; // Now warp the caster out of and back into here to refresh everyone's display @@ -272,17 +271,17 @@ void magic_unshroud(character_t *other_char) static void timer_callback_effect_npc_delete(TimerData *, tick_t, int npc_id) { - struct npc_data *effect_npc = (struct npc_data *) map_id2bl(npc_id); + dumb_ptr<npc_data> effect_npc = map_id_as_npc(npc_id); npc_free(effect_npc); } static -struct npc_data *local_spell_effect(int m, int x, int y, int effect, +dumb_ptr<npc_data> local_spell_effect(int m, int x, int y, int effect, interval_t tdelay) { /* 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, + dumb_ptr<npc_data> effect_npc = npc_spawn_text(m, x, y, INVISIBLE_NPC, "", "?"); int effect_npc_id = effect_npc->bl_id; @@ -319,16 +318,16 @@ int op_sfx(env_t *, int, val_t *args) static int op_instaheal(env_t *env, int, val_t *args) { - entity_t *caster = (VAR(VAR_CASTER).ty == TYPE::ENTITY) + dumb_ptr<block_list> caster = (VAR(VAR_CASTER).ty == TYPE::ENTITY) ? map_id2bl(VAR(VAR_CASTER).v.v_int) : NULL; - entity_t *subject = ARGENTITY(0); + dumb_ptr<block_list> subject = ARGENTITY(0); if (!caster) caster = subject; if (caster->bl_type == BL::PC && subject->bl_type == BL::PC) { - character_t *caster_pc = (character_t *) caster; - character_t *subject_pc = (character_t *) subject; + dumb_ptr<map_session_data> caster_pc = caster->as_player(); + dumb_ptr<map_session_data> subject_pc = subject->as_player(); MAP_LOG_PC(caster_pc, "SPELLHEAL-INSTA PC%d FOR %d", subject_pc->status.char_id, ARGINT(1)); } @@ -340,10 +339,10 @@ int op_instaheal(env_t *env, int, val_t *args) static int op_itemheal(env_t *env, int args_nr, val_t *args) { - entity_t *subject = ARGENTITY(0); + dumb_ptr<block_list> subject = ARGENTITY(0); if (subject->bl_type == BL::PC) { - pc_itemheal((struct map_session_data *) subject, + pc_itemheal(subject->as_player(), ARGINT(1), ARGINT(2)); } else @@ -365,12 +364,12 @@ ENUM_BITWISE_OPERATORS(Shroud) using e::Shroud; // differs from ARGPC by checking -#define ARGCHAR(n) (ENTITY_TYPE(n) == BL::PC) ? (character_t *)(ARGENTITY(n)) : NULL +#define ARGCHAR(n) (ARGENTITY(n)->is_player()) static int op_shroud(env_t *, int, val_t *args) { - character_t *subject = ARGCHAR(0); + dumb_ptr<map_session_data> subject = ARGCHAR(0); Shroud arg = static_cast<Shroud>(ARGINT(1)); if (!subject) @@ -389,7 +388,7 @@ int op_shroud(env_t *, int, val_t *args) static int op_reveal(env_t *, int, val_t *args) { - character_t *subject = ARGCHAR(0); + dumb_ptr<map_session_data> subject = ARGCHAR(0); if (subject && subject->state.shroud_active) magic_unshroud(subject); @@ -400,7 +399,7 @@ int op_reveal(env_t *, int, val_t *args) static int op_message(env_t *, int, val_t *args) { - character_t *subject = ARGCHAR(0); + dumb_ptr<map_session_data> subject = ARGCHAR(0); if (subject) clif_displaymessage(subject->fd, ARGSTR(1)); @@ -411,7 +410,7 @@ int op_message(env_t *, int, val_t *args) static void timer_callback_kill_npc(TimerData *, tick_t, int npc_id) { - struct npc_data *npc = (struct npc_data *) map_id2bl(npc_id); + dumb_ptr<npc_data> npc = map_id_as_npc(npc_id); if (npc) npc_free(npc); } @@ -419,7 +418,7 @@ void timer_callback_kill_npc(TimerData *, tick_t, int npc_id) static int op_messenger_npc(env_t *, int, val_t *args) { - struct npc_data *npc; + dumb_ptr<npc_data> npc; location_t *loc = &ARGLOCATION(0); npc = npc_spawn_text(loc->m, loc->x, loc->y, @@ -434,7 +433,7 @@ int op_messenger_npc(env_t *, int, val_t *args) } static -void entity_warp(entity_t *target, int destm, int destx, int desty) +void entity_warp(dumb_ptr<block_list> target, int destm, int destx, int desty) { if (target->bl_type == BL::PC || target->bl_type == BL::MOB) { @@ -443,7 +442,7 @@ void entity_warp(entity_t *target, int destm, int destx, int desty) { case BL::PC: { - character_t *character = (character_t *) target; + dumb_ptr<map_session_data> character = target->as_player(); char *map_name; clif_clearchar(character, BeingRemoveWhy::WARPED); map_delblock(character); @@ -467,7 +466,7 @@ void entity_warp(entity_t *target, int destm, int destx, int desty) target->bl_x = destx; target->bl_y = desty; target->bl_m = destm; - clif_fixmobpos((struct mob_data *) target); + clif_fixmobpos(target->as_mob()); break; } } @@ -476,7 +475,7 @@ void entity_warp(entity_t *target, int destm, int destx, int desty) static int op_move(env_t *, int, val_t *args) { - entity_t *subject = ARGENTITY(0); + dumb_ptr<block_list> subject = ARGENTITY(0); DIR dir = ARGDIR(1); int newx = subject->bl_x + dirx[dir]; @@ -491,7 +490,7 @@ int op_move(env_t *, int, val_t *args) static int op_warp(env_t *, int, val_t *args) { - entity_t *subject = ARGENTITY(0); + dumb_ptr<block_list> subject = ARGENTITY(0); location_t *loc = &ARGLOCATION(1); entity_warp(subject, loc->m, loc->x, loc->y); @@ -502,11 +501,11 @@ int op_warp(env_t *, int, val_t *args) static int op_banish(env_t *, int, val_t *args) { - entity_t *subject = ARGENTITY(0); + dumb_ptr<block_list> subject = ARGENTITY(0); if (subject->bl_type == BL::MOB) { - struct mob_data *mob = (struct mob_data *) subject; + dumb_ptr<mob_data> mob = subject->as_mob(); if (bool(mob->mode & MobMode::SUMMONED)) mob_catch_delete(mob, BeingRemoveWhy::WARPED); @@ -516,7 +515,7 @@ int op_banish(env_t *, int, val_t *args) } static -void record_status_change(invocation_t *invocation, int bl_id, +void record_status_change(dumb_ptr<invocation> invocation, int bl_id, StatusChange sc_id) { int index = invocation->status_change_refs_nr++; @@ -533,10 +532,10 @@ void record_status_change(invocation_t *invocation, int bl_id, static int op_status_change(env_t *env, int, val_t *args) { - entity_t *subject = ARGENTITY(0); + dumb_ptr<block_list> subject = ARGENTITY(0); int invocation_id = VAR(VAR_INVOCATION).ty == TYPE::INVOCATION ? VAR(VAR_INVOCATION).v.v_int : 0; - invocation_t *invocation = (invocation_t *) map_id2bl(invocation_id); + dumb_ptr<invocation> invocation_ = map_id_as_spell(invocation_id); assert (!ARGINT(3)); assert (!ARGINT(4)); @@ -545,8 +544,8 @@ int op_status_change(env_t *env, int, val_t *args) ARGINT(2), static_cast<interval_t>(ARGINT(6)), invocation_id); - if (invocation && subject->bl_type == BL::PC) - record_status_change(invocation, subject->bl_id, StatusChange(ARGINT(1))); + if (invocation_ && subject->bl_type == BL::PC) + record_status_change(invocation_, subject->bl_id, StatusChange(ARGINT(1))); return 0; } @@ -554,7 +553,7 @@ int op_status_change(env_t *env, int, val_t *args) static int op_stop_status_change(env_t *, int, val_t *args) { - entity_t *subject = ARGENTITY(0); + dumb_ptr<block_list> subject = ARGENTITY(0); StatusChange sc = static_cast<StatusChange>(ARGINT(1)); skill_status_change_end(subject, sc, nullptr); @@ -565,24 +564,23 @@ int op_stop_status_change(env_t *, int, val_t *args) static int op_override_attack(env_t *env, int, val_t *args) { - entity_t *psubject = ARGENTITY(0); + dumb_ptr<block_list> psubject = ARGENTITY(0); int charges = ARGINT(1); interval_t attack_delay = static_cast<interval_t>(ARGINT(2)); int attack_range = ARGINT(3); StatusChange icon = StatusChange(ARGINT(4)); int look = ARGINT(5); int stopattack = ARGINT(6); - character_t *subject; + dumb_ptr<map_session_data> subject; if (psubject->bl_type != BL::PC) return 0; - subject = (character_t *) psubject; + subject = psubject->as_player(); if (subject->attack_spell_override) { - invocation_t *old_invocation = - (invocation_t *) map_id2bl(subject->attack_spell_override); + dumb_ptr<invocation> old_invocation = map_id_as_spell(subject->attack_spell_override); if (old_invocation) spell_free_invocation(old_invocation); } @@ -593,8 +591,7 @@ int op_override_attack(env_t *env, int, val_t *args) if (subject->attack_spell_override) { - invocation_t *attack_spell = - (invocation_t *) map_id2bl(subject->attack_spell_override); + dumb_ptr<invocation> attack_spell = map_id_as_spell(subject->attack_spell_override); if (attack_spell && stopattack) attack_spell->flags |= INVOCATION_FLAG::STOPATTACK; @@ -609,15 +606,15 @@ static int op_create_item(env_t *, int, val_t *args) { struct item item; - entity_t *entity = ARGENTITY(0); - character_t *subject; + dumb_ptr<block_list> entity = ARGENTITY(0); + dumb_ptr<map_session_data> subject; int stackable; int count = ARGINT(2); if (count <= 0) return 0; if (entity->bl_type == BL::PC) - subject = (character_t *) entity; + subject = entity->as_player(); else return 0; @@ -646,13 +643,13 @@ bool AGGRAVATION_MODE_MAKES_AGGRESSIVE(int n) static int op_aggravate(env_t *, int, val_t *args) { - entity_t *victim = ARGENTITY(2); + dumb_ptr<block_list> victim = ARGENTITY(2); int mode = ARGINT(1); - entity_t *target = ARGENTITY(0); - struct mob_data *other; + dumb_ptr<block_list> target = ARGENTITY(0); + dumb_ptr<mob_data> other; if (target->bl_type == BL::MOB) - other = (struct mob_data *) target; + other = target->as_mob(); else return 0; @@ -682,17 +679,17 @@ static int op_spawn(env_t *, int, val_t *args) { area_t *area = ARGAREA(0); - entity_t *owner_e = ARGENTITY(1); + dumb_ptr<block_list> owner_e = ARGENTITY(1); int monster_id = ARGINT(2); MonsterAttitude monster_attitude = static_cast<MonsterAttitude>(ARGINT(3)); int monster_count = ARGINT(4); interval_t monster_lifetime = static_cast<interval_t>(ARGINT(5)); int i; - character_t *owner = NULL; + dumb_ptr<map_session_data> owner = NULL; if (monster_attitude == MonsterAttitude::SERVANT && owner_e->bl_type == BL::PC) - owner = (character_t *) owner_e; + owner = owner_e->as_player(); for (i = 0; i < monster_count; i++) { @@ -700,12 +697,12 @@ int op_spawn(env_t *, int, val_t *args) magic_random_location(&loc, area); int mob_id; - struct mob_data *mob; + dumb_ptr<mob_data> mob; mob_id = mob_once_spawn(owner, map[loc.m].name, loc.x, loc.y, "--ja--", // Is that needed? monster_id, 1, ""); - mob = (struct mob_data *) map_id2bl(mob_id); + mob = map_id_as_mob(mob_id); if (mob) { @@ -757,14 +754,14 @@ int op_spawn(env_t *, int, val_t *args) static const char *get_invocation_name(env_t *env) { - invocation_t *invocation; + dumb_ptr<invocation> invocation_; if (VAR(VAR_INVOCATION).ty != TYPE::INVOCATION) return "?"; - invocation = (invocation_t *) map_id2bl(VAR(VAR_INVOCATION).v.v_int); + invocation_ = map_id_as_spell(VAR(VAR_INVOCATION).v.v_int); - if (invocation) - return invocation->spell->name; + if (invocation_) + return invocation_->spell->name; else return "??"; } @@ -772,8 +769,8 @@ const char *get_invocation_name(env_t *env) static int op_injure(env_t *env, int, val_t *args) { - entity_t *caster = ARGENTITY(0); - entity_t *target = ARGENTITY(1); + dumb_ptr<block_list> caster = ARGENTITY(0); + dumb_ptr<block_list> target = ARGENTITY(1); int damage_caused = ARGINT(2); int mp_damage = ARGINT(3); int target_hp = battle_get_hp(target); @@ -781,8 +778,8 @@ int op_injure(env_t *env, int, val_t *args) if (target->bl_type == BL::PC && !map[target->bl_m].flag.pvp - && !((character_t *) target)->special_state.killable - && (caster->bl_type != BL::PC || !((character_t *) caster)->special_state.killer)) + && !target->as_player()->special_state.killable + && (caster->bl_type != BL::PC || !caster->as_player()->special_state.killer)) return 0; /* Cannot damage other players outside of pvp */ if (target != caster) @@ -804,10 +801,10 @@ int op_injure(env_t *env, int, val_t *args) if (caster->bl_type == BL::PC) { - character_t *caster_pc = (character_t *) caster; + dumb_ptr<map_session_data> caster_pc = caster->as_player(); if (target->bl_type == BL::MOB) { - struct mob_data *mob = (struct mob_data *) target; + dumb_ptr<mob_data> mob = target->as_mob(); MAP_LOG_PC(caster_pc, "SPELLDMG MOB%d %d FOR %d BY %s", mob->bl_id, mob->mob_class, damage_caused, @@ -822,7 +819,7 @@ int op_injure(env_t *env, int, val_t *args) static int op_emote(env_t *, int, val_t *args) { - entity_t *victim = ARGENTITY(0); + dumb_ptr<block_list> victim = ARGENTITY(0); int emotion = ARGINT(1); clif_emotion(victim, emotion); @@ -832,7 +829,7 @@ int op_emote(env_t *, int, val_t *args) static int op_set_script_variable(env_t *, int, val_t *args) { - character_t *c = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : NULL; + dumb_ptr<map_session_data> c = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : NULL; if (!c) return 1; @@ -845,7 +842,7 @@ int op_set_script_variable(env_t *, int, val_t *args) static int op_set_hair_colour(env_t *, int, val_t *args) { - character_t *c = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : NULL; + dumb_ptr<map_session_data> c = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : NULL; if (!c) return 1; @@ -858,7 +855,7 @@ int op_set_hair_colour(env_t *, int, val_t *args) static int op_set_hair_style(env_t *, int, val_t *args) { - character_t *c = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : NULL; + dumb_ptr<map_session_data> c = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : NULL; if (!c) return 1; @@ -876,10 +873,10 @@ int op_drop_item_for (env_t *, int args_nr, val_t *args) location_t *loc = &ARGLOCATION(0); int count = ARGINT(2); interval_t interval = static_cast<interval_t>(ARGINT(3)); - character_t *c = ((args_nr > 4) && (ENTITY_TYPE(4) == BL::PC)) ? ARGPC(4) : NULL; + dumb_ptr<map_session_data> c = ((args_nr > 4) && (ENTITY_TYPE(4) == BL::PC)) ? ARGPC(4) : NULL; 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 }; + dumb_ptr<map_session_data> owners[3] = { c, NULL, NULL }; GET_ARG_ITEM(1, item, stackable); @@ -897,7 +894,7 @@ int op_drop_item_for (env_t *, int args_nr, val_t *args) static int op_gain_exp(env_t *, int, val_t *args) { - character_t *c = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : NULL; + dumb_ptr<map_session_data> c = (ENTITY_TYPE(0) == BL::PC) ? ARGPC(0) : NULL; if (!c) return 1; @@ -980,14 +977,14 @@ void spell_effect_report_termination(int invocation_id, int bl_id, { int i; int index = -1; - invocation_t *invocation = (invocation_t *) map_id2bl(invocation_id); + dumb_ptr<invocation> invocation_ = map_id_as_spell(invocation_id); - if (!invocation || invocation->bl_type != BL::SPELL) + if (!invocation_ || invocation_->bl_type != BL::SPELL) return; - for (i = 0; i < invocation->status_change_refs_nr; i++) + for (i = 0; i < invocation_->status_change_refs_nr; i++) { - status_change_ref_t *cr = &invocation->status_change_refs[i]; + status_change_ref_t *cr = &invocation_->status_change_refs[i]; if (cr->sc_type == sc_id && cr->bl_id == bl_id) { index = i; @@ -997,7 +994,7 @@ void spell_effect_report_termination(int invocation_id, int bl_id, if (index == -1) { - entity_t *entity = map_id2bl(bl_id); + dumb_ptr<block_list> entity = map_id2bl(bl_id); if (entity->bl_type == BL::PC) FPRINTF(stderr, "[magic] INTERNAL ERROR: spell-effect-report-termination: tried to terminate on unexpected bl %d, sc %d\n", @@ -1005,25 +1002,24 @@ void spell_effect_report_termination(int invocation_id, int bl_id, return; } - if (index == invocation->status_change_refs_nr - 1) - invocation->status_change_refs_nr--; + if (index == invocation_->status_change_refs_nr - 1) + invocation_->status_change_refs_nr--; else /* Copy last change ref to the one we are deleting */ - invocation->status_change_refs[index] = - invocation-> - status_change_refs[--invocation->status_change_refs_nr]; + invocation_->status_change_refs[index] = + invocation_->status_change_refs[--invocation_->status_change_refs_nr]; - try_to_finish_invocation(invocation); + try_to_finish_invocation(invocation_); } static -effect_t *return_to_stack(invocation_t *invocation) +effect_t *return_to_stack(dumb_ptr<invocation> invocation_) { - if (!invocation->stack_size) + if (!invocation_->stack_size) return NULL; else { cont_activation_record_t *ar = - invocation->stack + (invocation->stack_size - 1); + invocation_->stack + (invocation_->stack_size - 1); switch (ar->ty) { @@ -1035,13 +1031,13 @@ effect_t *return_to_stack(invocation_t *invocation) for (i = 0; i < ar->c.c_proc.args_nr; i++) { val_t *var = - &invocation->env->vars[ar->c.c_proc.formals[i]]; + &invocation_->env->vars[ar->c.c_proc.formals[i]]; magic_clear_var(var); *var = ar->c.c_proc.old_actuals[i]; } clear_activation_record(ar); - --invocation->stack_size; + --invocation_->stack_size; return ret; } @@ -1049,7 +1045,7 @@ effect_t *return_to_stack(invocation_t *invocation) case CONT_STACK::FOREACH: { int entity_id; - val_t *var = &invocation->env->vars[ar->c.c_foreach.id]; + val_t *var = &invocation_->env->vars[ar->c.c_foreach.id]; do { @@ -1057,7 +1053,7 @@ effect_t *return_to_stack(invocation_t *invocation) { effect_t *ret = ar->return_location; clear_activation_record(ar); - --invocation->stack_size; + --invocation_->stack_size; return ret; } @@ -1078,13 +1074,13 @@ effect_t *return_to_stack(invocation_t *invocation) { effect_t *ret = ar->return_location; clear_activation_record(ar); - --invocation->stack_size; + --invocation_->stack_size; return ret; } - magic_clear_var(&invocation->env->vars[ar->c.c_for.id]); - invocation->env->vars[ar->c.c_for.id].ty = TYPE::INT; - invocation->env->vars[ar->c.c_for.id].v.v_int = + magic_clear_var(&invocation_->env->vars[ar->c.c_for.id]); + invocation_->env->vars[ar->c.c_for.id].ty = TYPE::INT; + invocation_->env->vars[ar->c.c_for.id].v.v_int = ar->c.c_for.current++; return ar->c.c_for.body; @@ -1092,24 +1088,24 @@ effect_t *return_to_stack(invocation_t *invocation) default: FPRINTF(stderr, "[magic] INTERNAL ERROR: While executing spell `%s': stack corruption\n", - invocation->spell->name); + invocation_->spell->name); return NULL; } } } static -cont_activation_record_t *add_stack_entry(invocation_t *invocation, +cont_activation_record_t *add_stack_entry(dumb_ptr<invocation> invocation_, CONT_STACK ty, effect_t *return_location) { cont_activation_record_t *ar = - invocation->stack + invocation->stack_size++; - if (invocation->stack_size >= MAX_STACK_SIZE) + invocation_->stack + invocation_->stack_size++; + if (invocation_->stack_size >= MAX_STACK_SIZE) { FPRINTF(stderr, "[magic] Execution stack size exceeded in spell `%s'; truncating effect\n", - invocation->spell->name); - invocation->stack_size--; + invocation_->spell->name); + invocation_->stack_size--; return NULL; } @@ -1119,7 +1115,7 @@ cont_activation_record_t *add_stack_entry(invocation_t *invocation, } static -void find_entities_in_area_c(entity_t *target, +void find_entities_in_area_c(dumb_ptr<block_list> target, int *entities_allocd_p, int *entities_nr_p, int **entities_p, @@ -1145,7 +1141,7 @@ void find_entities_in_area_c(entity_t *target, break; else if (filter == FOREACH_FILTER::SPELL) { /* Check all spells bound to the caster */ - invocation_t *invoc = ((character_t *) target)->active_spells; + dumb_ptr<invocation> invoc = target->as_player()->active_spells; /* Add all spells locked onto thie PC */ while (invoc) @@ -1167,7 +1163,7 @@ void find_entities_in_area_c(entity_t *target, case BL::SPELL: if (filter == FOREACH_FILTER::SPELL) { - invocation_t *invocation = (invocation_t *) target; + dumb_ptr<invocation> invocation = target->as_spell(); /* Check whether the spell is `bound'-- if so, we'll consider it iff we see the caster(case BL::PC). */ if (bool(invocation->flags & INVOCATION_FLAG::BOUND)) @@ -1217,7 +1213,7 @@ void find_entities_in_area(area_t *area, int *entities_allocd_p, } static -effect_t *run_foreach(invocation_t *invocation, effect_t *foreach, +effect_t *run_foreach(dumb_ptr<invocation> invocation, effect_t *foreach, effect_t *return_location) { val_t area; @@ -1268,7 +1264,7 @@ effect_t *run_foreach(invocation_t *invocation, effect_t *foreach, } static -effect_t *run_for (invocation_t *invocation, effect_t *for_, +effect_t *run_for (dumb_ptr<invocation> invocation, effect_t *for_, effect_t *return_location) { cont_activation_record_t *ar; @@ -1303,7 +1299,7 @@ effect_t *run_for (invocation_t *invocation, effect_t *for_, } static -effect_t *run_call(invocation_t *invocation, +effect_t *run_call(dumb_ptr<invocation> invocation, effect_t *return_location) { effect_t *current = invocation->current_effect; @@ -1406,25 +1402,25 @@ void print_cfg(int i, effect_t *e) * -1 if we paused to wait for a user action (via script interaction) */ static -interval_t spell_run(invocation_t *invocation, int allow_delete) +interval_t spell_run(dumb_ptr<invocation> invocation_, int allow_delete) { - const int invocation_id = invocation->bl_id; -#define REFRESH_INVOCATION invocation = (invocation_t *) map_id2bl(invocation_id); if (!invocation) return interval_t::zero(); + const int invocation_id = invocation_->bl_id; +#define REFRESH_INVOCATION invocation_ = map_id_as_spell(invocation_id); if (!invocation_) return interval_t::zero(); #ifdef DEBUG FPRINTF(stderr, "Resuming execution: invocation of `%s'\n", - invocation->spell->name); - print_cfg(1, invocation->current_effect); + invocation_->spell->name); + print_cfg(1, invocation_->current_effect); #endif - while (invocation->current_effect) + while (invocation_->current_effect) { - effect_t *e = invocation->current_effect; + effect_t *e = invocation_->current_effect; effect_t *next = e->next; int i; #ifdef DEBUG FPRINTF(stderr, "Next step of type %d\n", e->ty); - dump_env(invocation->env); + dump_env(invocation_->env); #endif switch (e->ty) @@ -1433,30 +1429,30 @@ interval_t spell_run(invocation_t *invocation, int allow_delete) break; case EFFECT::ABORT: - invocation->flags |= INVOCATION_FLAG::ABORTED; - invocation->end_effect = NULL; + invocation_->flags |= INVOCATION_FLAG::ABORTED; + invocation_->end_effect = NULL; FALLTHROUGH; case EFFECT::END: - clear_stack(invocation); + clear_stack(invocation_); next = NULL; break; case EFFECT::ASSIGN: - magic_eval(invocation->env, - &invocation->env->vars[e->e.e_assign.id], + magic_eval(invocation_->env, + &invocation_->env->vars[e->e.e_assign.id], e->e.e_assign.expr); break; case EFFECT::FOREACH: - next = run_foreach(invocation, e, next); + next = run_foreach(invocation_, e, next); break; case EFFECT::FOR: - next = run_for (invocation, e, next); + next = run_for (invocation_, e, next); break; case EFFECT::IF: - if (magic_eval_int(invocation->env, e->e.e_if.cond)) + if (magic_eval_int(invocation_->env, e->e.e_if.cond)) next = e->e.e_if.true_branch; else next = e->e.e_if.false_branch; @@ -1465,8 +1461,8 @@ interval_t spell_run(invocation_t *invocation, int allow_delete) case EFFECT::SLEEP: { interval_t sleeptime = static_cast<interval_t>( - magic_eval_int(invocation->env, e->e.e_sleep)); - invocation->current_effect = next; + magic_eval_int(invocation_->env, e->e.e_sleep)); + invocation_->current_effect = next; if (sleeptime > interval_t::zero()) return sleeptime; break; @@ -1474,60 +1470,58 @@ interval_t spell_run(invocation_t *invocation, int allow_delete) case EFFECT::SCRIPT: { - character_t *caster = - (character_t *) map_id2bl(invocation->caster); + dumb_ptr<map_session_data> caster = map_id_as_player(invocation_->caster); if (caster) { - env_t *env = invocation->env; + env_t *env = invocation_->env; argrec_t arg[] = { {"@target", VAR(VAR_TARGET).ty == TYPE::ENTITY ? 0 : VAR(VAR_TARGET). v.v_int} , - {"@caster", invocation->caster} + {"@caster", invocation_->caster} , {"@caster_name$", caster ? caster->status.name : ""} }; int message_recipient = VAR(VAR_SCRIPTTARGET).ty == TYPE::ENTITY ? VAR(VAR_SCRIPTTARGET). - v.v_int : invocation->caster; - character_t *recipient = - (character_t *) map_id2bl(message_recipient); + v.v_int : invocation_->caster; + dumb_ptr<map_session_data> recipient = map_id_as_player(message_recipient); if (recipient->npc_id - && recipient->npc_id != invocation->bl_id) + && recipient->npc_id != invocation_->bl_id) break; /* Don't send multiple message boxes at once */ - if (!invocation->script_pos) // first time running this script? + if (!invocation_->script_pos) // first time running this script? clif_spawn_fake_npc_for_player(recipient, - invocation->bl_id); + invocation_->bl_id); // We have to do this or otherwise the client won't think that it's // dealing with an NPC int newpos = run_script_l(e->e.e_script, - invocation->script_pos, + invocation_->script_pos, message_recipient, - invocation->bl_id, + invocation_->bl_id, 3, arg); /* Returns the new script position, or -1 once the script is finished */ if (newpos != -1) { /* Must set up for continuation */ - recipient->npc_id = invocation->bl_id; - recipient->npc_pos = invocation->script_pos = newpos; + recipient->npc_id = invocation_->bl_id; + recipient->npc_pos = invocation_->script_pos = newpos; return static_cast<interval_t>(-1); /* Signal `wait for script' */ } else - invocation->script_pos = 0; - clif_clearchar_id(invocation->bl_id, BeingRemoveWhy::DEAD, caster->fd); + invocation_->script_pos = 0; + clif_clearchar_id(invocation_->bl_id, BeingRemoveWhy::DEAD, caster->fd); } REFRESH_INVOCATION; // Script may have killed the caster break; } case EFFECT::BREAK: - next = return_to_stack(invocation); + next = return_to_stack(invocation_); break; case EFFECT::OP: @@ -1536,13 +1530,13 @@ interval_t spell_run(invocation_t *invocation, int allow_delete) val_t args[MAX_ARGS]; for (i = 0; i < e->e.e_op.args_nr; i++) - magic_eval(invocation->env, &args[i], e->e.e_op.args[i]); + magic_eval(invocation_->env, &args[i], e->e.e_op.args[i]); if (!magic_signature_check("effect", op->name, op->signature, e->e.e_op.args_nr, args, e->e.e_op.line_nr, e->e.e_op.column)) - op->op(invocation->env, e->e.e_op.args_nr, args); + op->op(invocation_->env, e->e.e_op.args_nr, args); for (i = 0; i < e->e.e_op.args_nr; i++) magic_clear_var(&args[i]); @@ -1552,7 +1546,7 @@ interval_t spell_run(invocation_t *invocation, int allow_delete) } case EFFECT::CALL: - next = run_call(invocation, next); + next = run_call(invocation_, next); break; default: @@ -1562,19 +1556,19 @@ interval_t spell_run(invocation_t *invocation, int allow_delete) } if (!next) - next = return_to_stack(invocation); + next = return_to_stack(invocation_); - invocation->current_effect = next; + invocation_->current_effect = next; } if (allow_delete) - try_to_finish_invocation(invocation); + try_to_finish_invocation(invocation_); return interval_t::zero(); #undef REFRESH_INVOCATION } static -void spell_execute_d(invocation_t *invocation, int allow_deletion) +void spell_execute_d(dumb_ptr<invocation> invocation, int allow_deletion) { spell_update_location(invocation); interval_t delta = spell_run(invocation, allow_deletion); @@ -1590,12 +1584,12 @@ void spell_execute_d(invocation_t *invocation, int allow_deletion) /* If 0, the script cleaned itself. If -1(wait-for-script), we must wait for the user. */ } -void spell_execute(invocation_t *invocation) +void spell_execute(dumb_ptr<invocation> invocation) { spell_execute_d(invocation, 1); } -void spell_execute_script(invocation_t *invocation) +void spell_execute_script(dumb_ptr<invocation> invocation) { if (invocation->script_pos) spell_execute_d(invocation, 1); @@ -1607,43 +1601,42 @@ void spell_execute_script(invocation_t *invocation) int spell_attack(int caster_id, int target_id) { - character_t *caster = (character_t *) map_id2bl(caster_id); - invocation_t *invocation; + dumb_ptr<map_session_data> caster = map_id_as_player(caster_id); + dumb_ptr<invocation> invocation_; int stop_attack = 0; if (!caster) return 0; - invocation = (invocation_t *) map_id2bl(caster->attack_spell_override); + invocation_ = map_id_as_spell(caster->attack_spell_override); - if (invocation && bool(invocation->flags & INVOCATION_FLAG::STOPATTACK)) + if (invocation_ && bool(invocation_->flags & INVOCATION_FLAG::STOPATTACK)) stop_attack = 1; - if (invocation && caster->attack_spell_charges > 0) + if (invocation_ && caster->attack_spell_charges > 0) { - magic_clear_var(&invocation->env->vars[VAR_TARGET]); - invocation->env->vars[VAR_TARGET].ty = TYPE::ENTITY; - invocation->env->vars[VAR_TARGET].v.v_int = target_id; + magic_clear_var(&invocation_->env->vars[VAR_TARGET]); + invocation_->env->vars[VAR_TARGET].ty = TYPE::ENTITY; + invocation_->env->vars[VAR_TARGET].v.v_int = target_id; - invocation->current_effect = invocation->trigger_effect; - invocation->flags &= ~INVOCATION_FLAG::ABORTED; - spell_execute_d(invocation, + invocation_->current_effect = invocation_->trigger_effect; + invocation_->flags &= ~INVOCATION_FLAG::ABORTED; + spell_execute_d(invocation_, 0 /* don't delete the invocation if done */ ); // If the caster died, we need to refresh here: - invocation = - (invocation_t *) map_id2bl(caster->attack_spell_override); + invocation_ = map_id_as_spell(caster->attack_spell_override); - if (invocation && !bool(invocation->flags & INVOCATION_FLAG::ABORTED)) // If we didn't abort: + if (invocation_ && !bool(invocation_->flags & INVOCATION_FLAG::ABORTED)) // If we didn't abort: caster->attack_spell_charges--; } - if (invocation && caster->attack_spell_override != invocation->bl_id) + if (invocation_ && caster->attack_spell_override != invocation_->bl_id) { /* Attack spell changed / was refreshed */ // spell_free_invocation(invocation); // [Fate] This would be a double free. } - else if (!invocation || caster->attack_spell_charges <= 0) + else if (!invocation_ || caster->attack_spell_charges <= 0) { caster->attack_spell_override = 0; char_set_weapon_icon(caster, 0, StatusChange::ZERO, 0); @@ -1652,8 +1645,8 @@ int spell_attack(int caster_id, int target_id) if (stop_attack) pc_stopattack(caster); - if (invocation) - spell_free_invocation(invocation); + if (invocation_) + spell_free_invocation(invocation_); } return 1; diff --git a/src/map/magic.cpp b/src/map/magic.cpp index 1377979..f6da29b 100644 --- a/src/map/magic.cpp +++ b/src/map/magic.cpp @@ -10,7 +10,7 @@ #undef DEBUG static -char *magic_preprocess_message(character_t *character, char *start, +char *magic_preprocess_message(dumb_ptr<map_session_data> character, char *start, char *end) { if (character->state.shroud_active @@ -56,7 +56,7 @@ char *magic_tokenise(char *src, char **parameter) return retval; } -int magic_message(character_t *caster, char *spell_, size_t) +int magic_message(dumb_ptr<map_session_data> caster, char *spell_, size_t) { if (pc_isdead(caster)) return 0; @@ -106,7 +106,7 @@ int magic_message(character_t *caster, char *spell_, size_t) if (effects) { - invocation_t *invocation = spell_instantiate(effects, env); + dumb_ptr<invocation> invocation = spell_instantiate(effects, env); spell_bind(caster, invocation); spell_execute(invocation); diff --git a/src/map/magic.hpp b/src/map/magic.hpp index 4b567ea..cc66eb4 100644 --- a/src/map/magic.hpp +++ b/src/map/magic.hpp @@ -1,13 +1,13 @@ #ifndef MAGIC_HPP #define MAGIC_HPP +#include "../common/dumb_ptr.hpp" + +#include "map.hpp" #include "skill.t.hpp" #define MAGIC_CONFIG_FILE "conf/magic.conf" -typedef struct map_session_data character_t; -typedef struct block_list entity_t; - struct invocation; /* Spell invocation */ /** @@ -21,14 +21,14 @@ struct invocation; /* Spell invocation */ * \return 1 or -1 if the input message was magic and was handled by this function, 0 otherwise. -1 is returned when the * message should not be repeated. */ -int magic_message(character_t *caster, char *spell, size_t spell_len); +int magic_message(dumb_ptr<map_session_data> caster, char *spell, size_t spell_len); /** * Removes the shroud from a character * * \param character The character to remove the shroud from */ -void magic_unshroud(character_t *character); +void magic_unshroud(dumb_ptr<map_session_data> character); /** * Notifies a running spell that a status_change timer triggered by the spell has expired @@ -63,18 +63,18 @@ const char *magic_find_anchor_invocation(const char *teleport_location); /** * Execute a spell invocation and sets up timers to finish */ -void spell_execute(struct invocation *invocation); +void spell_execute(dumb_ptr<invocation> invocation); /** * Continue an NPC script embedded in a spell */ -void spell_execute_script(struct invocation *invocation); +void spell_execute_script(dumb_ptr<invocation> invocation); /** * Stops all magic bound to the specified character * */ -void magic_stop_completely(character_t *c); +void magic_stop_completely(dumb_ptr<map_session_data> c); /** * Attacks with a magical spell charged to the character @@ -83,6 +83,6 @@ void magic_stop_completely(character_t *c); */ int spell_attack(int caster, int target); -void spell_free_invocation(struct invocation *invocation); +void spell_free_invocation(dumb_ptr<invocation> invocation); #endif // MAGIC_HPP diff --git a/src/map/map.cpp b/src/map/map.cpp index fd327ba..96e9f5e 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -27,6 +27,7 @@ #include "grfio.hpp" #include "itemdb.hpp" #include "magic.hpp" +#include "magic-interpreter.hpp" #include "mob.hpp" #include "npc.hpp" #include "party.hpp" @@ -38,13 +39,13 @@ #include "../poison.hpp" -DMap<int, struct block_list *> id_db; +DMap<int, dumb_ptr<block_list>> id_db; static DMap<std::string, struct map_data *> map_db; static -DMap<std::string, struct map_session_data *> nick_db; +DMap<std::string, dumb_ptr<map_session_data>> nick_db; struct charid2nick { @@ -58,7 +59,7 @@ Map<int, struct charid2nick> charid_db; static int users = 0; static -struct block_list *object[MAX_FLOORITEM]; +dumb_ptr<block_list> object[MAX_FLOORITEM]; static int first_free_object_id = 0, last_object_id = 0; @@ -106,12 +107,12 @@ int map_getusers(void) static int block_free_lock = 0; static -std::vector<struct block_list *> block_free; +std::vector<dumb_ptr<block_list>> block_free; -void MapBlockLock::freeblock(struct block_list *bl) +void MapBlockLock::freeblock(dumb_ptr<block_list> bl) { if (block_free_lock == 0) - free(bl); + bl.delete_(); else block_free.push_back(bl); } @@ -126,8 +127,8 @@ MapBlockLock::~MapBlockLock() assert (block_free_lock > 0); if ((--block_free_lock) == 0) { - for (struct block_list *bl : block_free) - free(bl); + for (dumb_ptr<block_list> bl : block_free) + bl.delete_(); block_free.clear(); } } @@ -145,13 +146,13 @@ struct block_list bl_head; * 既にlink済みかの確認が無い。危険かも *------------------------------------------ */ -int map_addblock(struct block_list *bl) +int map_addblock(dumb_ptr<block_list> bl) { int m, x, y; nullpo_ret(bl); - if (bl->bl_prev != NULL) + if (bl->bl_prev) { if (battle_config.error_log) PRINTF("map_addblock error : bl->bl_prev!=NULL\n"); @@ -169,7 +170,7 @@ int map_addblock(struct block_list *bl) { bl->bl_next = map[m].block_mob[x / BLOCK_SIZE + (y / BLOCK_SIZE) * map[m].bxs]; - bl->bl_prev = &bl_head; + bl->bl_prev = dumb_ptr<block_list>(&bl_head); if (bl->bl_next) bl->bl_next->bl_prev = bl; map[m].block_mob[x / BLOCK_SIZE + (y / BLOCK_SIZE) * map[m].bxs] = bl; @@ -180,7 +181,7 @@ int map_addblock(struct block_list *bl) { bl->bl_next = map[m].block[x / BLOCK_SIZE + (y / BLOCK_SIZE) * map[m].bxs]; - bl->bl_prev = &bl_head; + bl->bl_prev = dumb_ptr<block_list>(&bl_head); if (bl->bl_next) bl->bl_next->bl_prev = bl; map[m].block[x / BLOCK_SIZE + (y / BLOCK_SIZE) * map[m].bxs] = bl; @@ -197,15 +198,15 @@ int map_addblock(struct block_list *bl) * prevがNULLの場合listに繋がってない *------------------------------------------ */ -int map_delblock(struct block_list *bl) +int map_delblock(dumb_ptr<block_list> bl) { int b; nullpo_ret(bl); // 既にblocklistから抜けている - if (bl->bl_prev == NULL) + if (!bl->bl_prev) { - if (bl->bl_next != NULL) + if (bl->bl_next) { // prevがNULLでnextがNULLでないのは有ってはならない if (battle_config.error_log) @@ -221,7 +222,7 @@ int map_delblock(struct block_list *bl) if (bl->bl_next) bl->bl_next->bl_prev = bl->bl_prev; - if (bl->bl_prev == &bl_head) + if (bl->bl_prev == dumb_ptr<block_list>(&bl_head)) { // リストの頭なので、map[]のblock_listを更新する if (bl->bl_type == BL::MOB) @@ -254,7 +255,7 @@ int map_delblock(struct block_list *bl) int map_count_oncell(int m, int x, int y) { int bx, by; - struct block_list *bl = NULL; + dumb_ptr<block_list> bl = NULL; int i, c; int count = 0; @@ -288,12 +289,12 @@ int map_count_oncell(int m, int x, int y) * type!=0 ならその種類のみ *------------------------------------------ */ -void map_foreachinarea(std::function<void(struct block_list *)> func, +void map_foreachinarea(std::function<void(dumb_ptr<block_list>)> func, int m, int x0, int y0, int x1, int y1, BL type) { - std::vector<struct block_list *> bl_list; + std::vector<dumb_ptr<block_list>> bl_list; if (m < 0) return; @@ -310,7 +311,7 @@ void map_foreachinarea(std::function<void(struct block_list *)> func, { for (int bx = x0 / BLOCK_SIZE; bx <= x1 / BLOCK_SIZE; bx++) { - struct block_list *bl = map[m].block[bx + by * map[m].bxs]; + dumb_ptr<block_list> bl = map[m].block[bx + by * map[m].bxs]; int c = map[m].block_count[bx + by * map[m].bxs]; for (int i = 0; i < c && bl; i++, bl = bl->bl_next) { @@ -329,7 +330,7 @@ void map_foreachinarea(std::function<void(struct block_list *)> func, { for (int bx = x0 / BLOCK_SIZE; bx <= x1 / BLOCK_SIZE; bx++) { - struct block_list *bl = map[m].block_mob[bx + by * map[m].bxs]; + dumb_ptr<block_list> bl = map[m].block_mob[bx + by * map[m].bxs]; int c = map[m].block_mob_count[bx + by * map[m].bxs]; for (int i = 0; i < c && bl; i++, bl = bl->bl_next) { @@ -344,7 +345,7 @@ void map_foreachinarea(std::function<void(struct block_list *)> func, MapBlockLock lock; - for (struct block_list *bl : bl_list) + for (dumb_ptr<block_list> bl : bl_list) if (bl->bl_prev) func(bl); } @@ -357,13 +358,13 @@ void map_foreachinarea(std::function<void(struct block_list *)> func, * dx,dyは-1,0,1のみとする(どんな値でもいいっぽい?) *------------------------------------------ */ -void map_foreachinmovearea(std::function<void(struct block_list *)> func, +void map_foreachinmovearea(std::function<void(dumb_ptr<block_list>)> func, int m, int x0, int y0, int x1, int y1, int dx, int dy, BL type) { - std::vector<struct block_list *> bl_list; + std::vector<dumb_ptr<block_list>> bl_list; // Note: the x0, y0, x1, y1 are bl.bl_x, bl.bl_y ± AREA_SIZE, // but only a small subset actually needs to be done. if (dx == 0 || dy == 0) @@ -396,7 +397,7 @@ void map_foreachinmovearea(std::function<void(struct block_list *)> func, { for (int bx = x0 / BLOCK_SIZE; bx <= x1 / BLOCK_SIZE; bx++) { - struct block_list *bl = map[m].block[bx + by * map[m].bxs]; + dumb_ptr<block_list> bl = map[m].block[bx + by * map[m].bxs]; int c = map[m].block_count[bx + by * map[m].bxs]; for (int i = 0; i < c && bl; i++, bl = bl->bl_next) { @@ -439,7 +440,7 @@ void map_foreachinmovearea(std::function<void(struct block_list *)> func, { for (int bx = x0 / BLOCK_SIZE; bx <= x1 / BLOCK_SIZE; bx++) { - struct block_list *bl = map[m].block[bx + by * map[m].bxs]; + dumb_ptr<block_list> bl = map[m].block[bx + by * map[m].bxs]; int c = map[m].block_count[bx + by * map[m].bxs]; for (int i = 0; i < c && bl; i++, bl = bl->bl_next) { @@ -478,7 +479,7 @@ void map_foreachinmovearea(std::function<void(struct block_list *)> func, MapBlockLock lock; - for (struct block_list *bl : bl_list) + for (dumb_ptr<block_list> bl : bl_list) if (bl->bl_prev) func(bl); } @@ -487,18 +488,18 @@ void map_foreachinmovearea(std::function<void(struct block_list *)> func, // which only checks the exact single x/y passed to it rather than an // area radius - may be more useful in some instances) // -void map_foreachincell(std::function<void(struct block_list *)> func, +void map_foreachincell(std::function<void(dumb_ptr<block_list>)> func, int m, int x, int y, BL type) { - std::vector<struct block_list *> bl_list; + std::vector<dumb_ptr<block_list>> bl_list; int by = y / BLOCK_SIZE; int bx = x / BLOCK_SIZE; if (type == BL::NUL || type != BL::MOB) { - struct block_list *bl = map[m].block[bx + by * map[m].bxs]; + dumb_ptr<block_list> bl = map[m].block[bx + by * map[m].bxs]; int c = map[m].block_count[bx + by * map[m].bxs]; for (int i = 0; i < c && bl; i++, bl = bl->bl_next) { @@ -513,7 +514,7 @@ void map_foreachincell(std::function<void(struct block_list *)> func, if (type == BL::NUL || type == BL::MOB) { - struct block_list *bl = map[m].block_mob[bx + by * map[m].bxs]; + dumb_ptr<block_list> bl = map[m].block_mob[bx + by * map[m].bxs]; int c = map[m].block_mob_count[bx + by * map[m].bxs]; for (int i = 0; i < c && bl; i++, bl = bl->bl_next) { @@ -526,7 +527,7 @@ void map_foreachincell(std::function<void(struct block_list *)> func, MapBlockLock lock; - for (struct block_list *bl : bl_list) + for (dumb_ptr<block_list> bl : bl_list) if (bl->bl_prev) func(bl); } @@ -538,10 +539,10 @@ void map_foreachincell(std::function<void(struct block_list *)> func, * bl->bl_idもこの中で設定して問題無い? *------------------------------------------ */ -int map_addobject(struct block_list *bl) +int map_addobject(dumb_ptr<block_list> bl) { int i; - if (bl == NULL) + if (!bl) { PRINTF("map_addobject nullpo?\n"); return 0; @@ -549,7 +550,7 @@ int map_addobject(struct block_list *bl) if (first_free_object_id < 2 || first_free_object_id >= MAX_FLOORITEM) first_free_object_id = 2; for (i = first_free_object_id; i < MAX_FLOORITEM; i++) - if (object[i] == NULL) + if (!object[i]) break; if (i >= MAX_FLOORITEM) { @@ -572,7 +573,7 @@ int map_addobject(struct block_list *bl) */ int map_delobjectnofree(int id, BL type) { - if (object[id] == NULL) + if (!object[id]) return 0; if (object[id]->bl_type != type) @@ -584,9 +585,9 @@ int map_delobjectnofree(int id, BL type) } map_delblock(object[id]); - id_db.put(id, nullptr); + id_db.put(id, dumb_ptr<block_list>()); // map_freeblock(object[id]); - object[id] = NULL; + object[id] = nullptr; if (first_free_object_id > id) first_free_object_id = id; @@ -607,14 +608,14 @@ int map_delobjectnofree(int id, BL type) */ int map_delobject(int id, BL type) { - struct block_list *obj = object[id]; + dumb_ptr<block_list> obj = object[id]; if (obj == NULL) return 0; map_delobjectnofree(id, type); if (obj->bl_type == BL::PC) // [Fate] Not sure where else to put this... I'm not sure where delobject for PCs is called from - pc_cleanup((struct map_session_data *) obj); + pc_cleanup(obj->as_player()); MapBlockLock::freeblock(obj); @@ -626,10 +627,10 @@ int map_delobject(int id, BL type) * *------------------------------------------ */ -void map_foreachobject(std::function<void(struct block_list *)> func, +void map_foreachobject(std::function<void(dumb_ptr<block_list>)> func, BL type) { - std::vector<struct block_list *> bl_list; + std::vector<dumb_ptr<block_list>> bl_list; for (int i = 2; i <= last_object_id; i++) { if (!object[i]) @@ -643,7 +644,7 @@ void map_foreachobject(std::function<void(struct block_list *)> func, MapBlockLock lock; - for (struct block_list *bl : bl_list) + for (dumb_ptr<block_list> bl : bl_list) if (bl->bl_prev || bl->bl_next) func(bl); } @@ -660,15 +661,9 @@ void map_foreachobject(std::function<void(struct block_list *)> func, */ 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) - { - if (battle_config.error_log) - PRINTF("map_clearflooritem_timer : error\n"); - return; - } + dumb_ptr<block_list> obj = object[id]; + assert (obj && obj->bl_type == BL::ITEM); + dumb_ptr<flooritem_data> fitem = obj->as_item(); if (!tid) fitem->cleartimer.cancel(); clif_clearflooritem(fitem, 0); @@ -703,17 +698,17 @@ std::pair<uint16_t, uint16_t> map_searchrandfreecell(int m, int x, int y, int ra */ 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, + dumb_ptr<map_session_data> *owners, interval_t *owner_protection, interval_t lifetime, int dispersal) { - struct flooritem_data *fitem = NULL; + dumb_ptr<flooritem_data> fitem = NULL; nullpo_ret(item_data); auto xy = map_searchrandfreecell(m, x, y, dispersal); if (xy.first == 0 && xy.second == 0) return 0; - CREATE(fitem, struct flooritem_data, 1); + fitem.new_(); fitem->bl_type = BL::ITEM; fitem->bl_prev = fitem->bl_next = NULL; fitem->bl_m = m; @@ -729,7 +724,7 @@ int map_addflooritem_any(struct item *item_data, int amount, fitem->bl_id = map_addobject(fitem); if (fitem->bl_id == 0) { - free(fitem); + fitem.delete_(); return 0; } @@ -768,11 +763,11 @@ int map_addflooritem_any(struct item *item_data, int amount, 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) + dumb_ptr<map_session_data> first_sd, + dumb_ptr<map_session_data> second_sd, + dumb_ptr<map_session_data> third_sd) { - struct map_session_data *owners[3] = { first_sd, second_sd, third_sd }; + dumb_ptr<map_session_data> owners[3] = { first_sd, second_sd, third_sd }; interval_t owner_protection[3]; { @@ -804,7 +799,7 @@ void map_addchariddb(int charid, const char *name) * id_dbへblを追加 *------------------------------------------ */ -void map_addiddb(struct block_list *bl) +void map_addiddb(dumb_ptr<block_list> bl) { nullpo_retv(bl); @@ -815,7 +810,7 @@ void map_addiddb(struct block_list *bl) * id_dbからblを削除 *------------------------------------------ */ -void map_deliddb(struct block_list *bl) +void map_deliddb(dumb_ptr<block_list> bl) { nullpo_retv(bl); @@ -826,7 +821,7 @@ void map_deliddb(struct block_list *bl) * nick_dbへsdを追加 *------------------------------------------ */ -void map_addnickdb(struct map_session_data *sd) +void map_addnickdb(dumb_ptr<map_session_data> sd) { nullpo_retv(sd); @@ -839,7 +834,7 @@ void map_addnickdb(struct map_session_data *sd) * quit処理の主体が違うような気もしてきた *------------------------------------------ */ -void map_quit(struct map_session_data *sd) +void map_quit(dumb_ptr<map_session_data> sd) { nullpo_retv(sd); @@ -891,7 +886,7 @@ void map_quit(struct map_session_data *sd) * id番号のPCを探す。居なければNULL *------------------------------------------ */ -struct map_session_data *map_id2sd(int id) +dumb_ptr<map_session_data> map_id2sd(int id) { // This is bogus. // However, there might be differences for de-auth'ed accounts. @@ -902,7 +897,7 @@ struct map_session_data *map_id2sd(int id) // replaced by searching in all session. // by searching in session, we are sure that fd, session, and account exist. /* - struct block_list *bl; + dumb_ptr<block_list> bl; bl=numdb_search(id_db,id); if (bl && bl->bl_type==BL::PC) @@ -917,7 +912,7 @@ struct map_session_data *map_id2sd(int id) { map_session_data *sd = static_cast<map_session_data *>(session[i]->session_data.get()); if (sd->bl_id == id) - return sd; + return dumb_ptr<map_session_data>(sd); } } @@ -943,7 +938,7 @@ char *map_charid2nick(int id) /* [Fate] Operations to iterate over active map sessions */ static -struct map_session_data *map_get_session(int i) +dumb_ptr<map_session_data> map_get_session(int i) { if (i >= 0 && i < fd_max) { @@ -951,18 +946,18 @@ struct map_session_data *map_get_session(int i) return nullptr; map_session_data *d = static_cast<map_session_data *>(session[i]->session_data.get()); if (d && d->state.auth) - return d; + return dumb_ptr<map_session_data>(d); } return NULL; } static -struct map_session_data *map_get_session_forward(int start) +dumb_ptr<map_session_data> map_get_session_forward(int start) { for (int i = start; i < fd_max; i++) { - struct map_session_data *d = map_get_session(i); + dumb_ptr<map_session_data> d = map_get_session(i); if (d) return d; } @@ -971,12 +966,12 @@ struct map_session_data *map_get_session_forward(int start) } static -struct map_session_data *map_get_session_backward(int start) +dumb_ptr<map_session_data> map_get_session_backward(int start) { int i; for (i = start; i >= 0; i--) { - struct map_session_data *d = map_get_session(i); + dumb_ptr<map_session_data> d = map_get_session(i); if (d) return d; } @@ -984,22 +979,22 @@ struct map_session_data *map_get_session_backward(int start) return NULL; } -struct map_session_data *map_get_first_session(void) +dumb_ptr<map_session_data> map_get_first_session(void) { return map_get_session_forward(0); } -struct map_session_data *map_get_next_session(struct map_session_data *d) +dumb_ptr<map_session_data> map_get_next_session(dumb_ptr<map_session_data> d) { return map_get_session_forward(d->fd + 1); } -struct map_session_data *map_get_last_session(void) +dumb_ptr<map_session_data> map_get_last_session(void) { return map_get_session_backward(fd_max); } -struct map_session_data *map_get_prev_session(struct map_session_data *d) +dumb_ptr<map_session_data> map_get_prev_session(dumb_ptr<map_session_data> d) { return map_get_session_backward(d->fd - 1); } @@ -1010,10 +1005,10 @@ struct map_session_data *map_get_prev_session(struct map_session_data *d) * return map_session_data pointer or NULL *------------------------------------------ */ -struct map_session_data *map_nick2sd(const char *nick) +dumb_ptr<map_session_data> map_nick2sd(const char *nick) { int i, quantity = 0, nicklen; - struct map_session_data *sd = NULL; + dumb_ptr<map_session_data> sd = NULL; if (nick == NULL) return NULL; @@ -1032,9 +1027,9 @@ struct map_session_data *map_nick2sd(const char *nick) { // Strict comparison (if found, we finish the function immediatly with correct value) if (strcmp(pl_sd->status.name, nick) == 0) - return pl_sd; + return dumb_ptr<map_session_data>(pl_sd); quantity++; - sd = pl_sd; + sd = dumb_ptr<map_session_data>(pl_sd); } } } @@ -1052,9 +1047,9 @@ struct map_session_data *map_nick2sd(const char *nick) * 一時objectの場合は配列を引くのみ *------------------------------------------ */ -struct block_list *map_id2bl(int id) +dumb_ptr<block_list> map_id2bl(int id) { - struct block_list *bl = NULL; + dumb_ptr<block_list> bl = NULL; if (id < sizeof(object) / sizeof(object[0])) bl = object[id]; else @@ -1067,7 +1062,7 @@ struct block_list *map_id2bl(int id) * map.npcへ追加 (warp等の領域持ちのみ) *------------------------------------------ */ -int map_addnpc(int m, struct npc_data *nd) +int map_addnpc(int m, dumb_ptr<npc_data> nd) { int i; if (m < 0 || m >= map_num) @@ -1090,7 +1085,7 @@ int map_addnpc(int m, struct npc_data *nd) map[m].npc[i] = nd; nd->n = i; - id_db.put(nd->bl_id, (struct block_list *)nd); + id_db.put(nd->bl_id, (dumb_ptr<block_list>)nd); return i; } @@ -1114,8 +1109,7 @@ void map_removenpc(void) // free(map[m].npc[i]->u.scr.script); // free(map[m].npc[i]->u.scr.label_list); } - free(map[m].npc[i]); - map[m].npc[i] = NULL; + map[m].npc[i].delete_(); n++; } } @@ -1172,7 +1166,7 @@ bool map_check_dir(const DIR s_dir, const DIR t_dir) * 彼我の方向を計算 *------------------------------------------ */ -DIR map_calc_dir(struct block_list *src, int x, int y) +DIR map_calc_dir(dumb_ptr<block_list> src, int x, int y) { DIR dir = DIR::S; int dx, dy; @@ -1325,8 +1319,8 @@ bool map_readmap(int m, const_string fn) map[m].bys = (ys + BLOCK_SIZE - 1) / BLOCK_SIZE; size_t size = map[m].bxs * map[m].bys; - CREATE(map[m].block, struct block_list *, size); - CREATE(map[m].block_mob, struct block_list *, size); + CREATE(map[m].block, dumb_ptr<block_list>, size); + CREATE(map[m].block_mob, dumb_ptr<block_list>, size); CREATE(map[m].block_count, int, size); CREATE(map[m].block_mob_count, int, size); @@ -1617,7 +1611,7 @@ int map_config_read(const char *cfgName) } static -void cleanup_sub(struct block_list *bl) +void cleanup_sub(dumb_ptr<block_list> bl) { nullpo_retv(bl); @@ -1627,16 +1621,16 @@ void cleanup_sub(struct block_list *bl) map_delblock(bl); // There is something better... break; case BL::NPC: - npc_delete((struct npc_data *) bl); + npc_delete(bl->as_npc()); break; case BL::MOB: - mob_delete((struct mob_data *) bl); + mob_delete(bl->as_mob()); break; case BL::ITEM: map_clearflooritem(bl->bl_id); break; case BL::SPELL: - spell_free_invocation((struct invocation *) bl); + spell_free_invocation(bl->as_spell()); break; } } @@ -1756,9 +1750,9 @@ int do_init(int argc, char *argv[]) return 0; } -int map_scriptcont(struct map_session_data *sd, int id) +int map_scriptcont(dumb_ptr<map_session_data> sd, int id) { - struct block_list *bl = map_id2bl(id); + dumb_ptr<block_list> bl = map_id2bl(id); if (!bl) return 0; @@ -1768,7 +1762,7 @@ int map_scriptcont(struct map_session_data *sd, int id) case BL::NPC: return npc_scriptcont(sd, id); case BL::SPELL: - spell_execute_script((struct invocation *) bl); + spell_execute_script(bl->as_spell()); break; } diff --git a/src/map/map.hpp b/src/map/map.hpp index c3b4593..cb2513a 100644 --- a/src/map/map.hpp +++ b/src/map/map.hpp @@ -35,15 +35,35 @@ constexpr int MAX_DROP_PER_MAP = 48; constexpr interval_t DEFAULT_AUTOSAVE_INTERVAL = std::chrono::minutes(1); +struct map_session_data; +struct npc_data; +struct mob_data; +struct flooritem_data; +struct invocation; + struct block_list { - struct block_list *bl_next, *bl_prev; + dumb_ptr<block_list> bl_next, bl_prev; int bl_id; short bl_m, bl_x, bl_y; BL bl_type; -#warning "This is important!" - // virtual ~block_list() {} + // This deletes the copy-ctor also + // TODO give proper ctors. + block_list& operator = (block_list&&) = delete; + virtual ~block_list() {} + + dumb_ptr<map_session_data> as_player(); + dumb_ptr<npc_data> as_npc(); + dumb_ptr<mob_data> as_mob(); + dumb_ptr<flooritem_data> as_item(); + dumb_ptr<invocation> as_spell(); + + dumb_ptr<map_session_data> is_player(); + dumb_ptr<npc_data> is_npc(); + dumb_ptr<mob_data> is_mob(); + dumb_ptr<flooritem_data> is_item(); + dumb_ptr<invocation> is_spell(); }; struct walkpath_data @@ -155,7 +175,7 @@ struct map_session_data : block_list, SessionData int followtarget; 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 + dumb_ptr<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. // Weapon equipment slot (slot 4) item override @@ -279,6 +299,11 @@ struct npc_item_list { int nameid, value; }; + +class npc_data_script; +class npc_data_shop; +class npc_data_warp; +class npc_data_message; struct npc_data : block_list { NpcSubtype npc_subtype; @@ -288,41 +313,66 @@ struct npc_data : block_list interval_t speed; char name[24]; char exname[24]; - int chat_id; Opt1 opt1; Opt2 opt2; Opt3 opt3; Option option; short flag; - union - { - struct - { - const ScriptCode *script; - short xs, ys; - interval_t timer; - Timer timerid; - int timeramount, nexttimer; - tick_t timertick; - struct npc_timerevent_list *timer_event; - int label_list_num; - struct npc_label_list *label_list; - int src_id; - } scr; - struct npc_item_list shop_item[1]; - struct - { - short xs, ys; - short x, y; - char name[16]; - } warp; - char *message; // for NpcSubtype::MESSAGE: only send this message - } u; - // ここにメンバを追加してはならない(shop_itemが可変長の為) char eventqueue[MAX_EVENTQUEUE][50]; Timer eventtimer[MAX_EVENTTIMER]; short arenaflag; + + dumb_ptr<npc_data_script> as_script(); + dumb_ptr<npc_data_shop> as_shop(); + dumb_ptr<npc_data_warp> as_warp(); + dumb_ptr<npc_data_message> as_message(); + + dumb_ptr<npc_data_script> is_script(); + dumb_ptr<npc_data_shop> is_shop(); + dumb_ptr<npc_data_warp> is_warp(); + dumb_ptr<npc_data_message> is_message(); +}; + +class npc_data_script : public npc_data +{ +public: + struct + { + const ScriptCode *script; + short xs, ys; + interval_t timer; + Timer timerid; + int timeramount, nexttimer; + tick_t timertick; + struct npc_timerevent_list *timer_event; + int label_list_num; + struct npc_label_list *label_list; + int src_id; + } scr; +}; + +class npc_data_shop : public npc_data +{ +public: + std::vector<npc_item_list> shop_items; +}; + +class npc_data_warp : public npc_data +{ +public: + struct + { + short xs, ys; + short x, y; + char name[16]; + } warp; +}; + +class npc_data_message : public npc_data +{ +public: + char *message; }; constexpr int MOB_XP_BONUS_BASE = 1024; @@ -400,8 +450,8 @@ struct map_data char alias[24]; // [MouseJstr] // if NULL, actually a map_data_other_server std::unique_ptr<MapCell[]> gat; - struct block_list **block; - struct block_list **block_mob; + dumb_ptr<block_list> *block; + dumb_ptr<block_list> *block_mob; int *block_count, *block_mob_count; int m; short xs, ys; @@ -436,7 +486,7 @@ struct map_data unsigned town:1; // [remoitnane] } flag; struct point save; - struct npc_data *npc[MAX_NPC_PER_MAP]; + dumb_ptr<npc_data> npc[MAX_NPC_PER_MAP]; struct { int drop_id; @@ -496,21 +546,21 @@ public: ~MapBlockLock(); static - void freeblock(struct block_list *); + void freeblock(dumb_ptr<block_list>); }; -int map_addblock(struct block_list *); -int map_delblock(struct block_list *); -void map_foreachinarea(std::function<void(struct block_list *)>, +int map_addblock(dumb_ptr<block_list>); +int map_delblock(dumb_ptr<block_list>); +void map_foreachinarea(std::function<void(dumb_ptr<block_list>)>, int, int, int, int, int, BL); // -- moonsoul (added map_foreachincell) -void map_foreachincell(std::function<void(struct block_list *)>, +void map_foreachincell(std::function<void(dumb_ptr<block_list>)>, int, int, int, BL); -void map_foreachinmovearea(std::function<void(struct block_list *)>, +void map_foreachinmovearea(std::function<void(dumb_ptr<block_list>)>, int, int, int, int, int, int, int, @@ -518,15 +568,15 @@ void map_foreachinmovearea(std::function<void(struct block_list *)>, //block関連に追加 int map_count_oncell(int m, int x, int y); // 一時的object関連 -int map_addobject(struct block_list *); +int map_addobject(dumb_ptr<block_list>); int map_delobject(int, BL type); int map_delobjectnofree(int id, BL type); -void map_foreachobject(std::function<void(struct block_list *)>, +void map_foreachobject(std::function<void(dumb_ptr<block_list>)>, BL); // -void map_quit(struct map_session_data *); +void map_quit(dumb_ptr<map_session_data>); // npc -int map_addnpc(int, struct npc_data *); +int map_addnpc(int, dumb_ptr<npc_data>); void map_log(const_string line); #define MAP_LOG(format, ...) \ @@ -544,36 +594,100 @@ void map_clearflooritem(int id) 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, interval_t *owner_protection, + dumb_ptr<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 *); + dumb_ptr<map_session_data>, dumb_ptr<map_session_data>, + dumb_ptr<map_session_data>); // キャラid=>キャラ名 変換関連 extern -DMap<int, struct block_list *> id_db; +DMap<int, dumb_ptr<block_list>> id_db; void map_addchariddb(int charid, const char *name); char *map_charid2nick(int); -struct map_session_data *map_id2sd(int); -struct block_list *map_id2bl(int); +dumb_ptr<map_session_data> map_id2sd(int); +dumb_ptr<block_list> map_id2bl(int); + +inline +dumb_ptr<map_session_data> map_id_as_player(int id) +{ + dumb_ptr<block_list> bl = map_id2bl(id); + return bl ? bl->as_player() : nullptr; +} +inline +dumb_ptr<npc_data> map_id_as_npc(int id) +{ + dumb_ptr<block_list> bl = map_id2bl(id); + return bl ? bl->as_npc() : nullptr; +} +inline +dumb_ptr<mob_data> map_id_as_mob(int id) +{ + dumb_ptr<block_list> bl = map_id2bl(id); + return bl ? bl->as_mob() : nullptr; +} +inline +dumb_ptr<flooritem_data> map_id_as_item(int id) +{ + dumb_ptr<block_list> bl = map_id2bl(id); + return bl ? bl->as_item() : nullptr; +} +inline +dumb_ptr<invocation> map_id_as_spell(int id) +{ + dumb_ptr<block_list> bl = map_id2bl(id); + return bl ? bl->as_spell() : nullptr; +} + +inline +dumb_ptr<map_session_data> map_id_is_player(int id) +{ + dumb_ptr<block_list> bl = map_id2bl(id); + return bl ? bl->is_player() : nullptr; +} +inline +dumb_ptr<npc_data> map_id_is_npc(int id) +{ + dumb_ptr<block_list> bl = map_id2bl(id); + return bl ? bl->is_npc() : nullptr; +} +inline +dumb_ptr<mob_data> map_id_is_mob(int id) +{ + dumb_ptr<block_list> bl = map_id2bl(id); + return bl ? bl->is_mob() : nullptr; +} +inline +dumb_ptr<flooritem_data> map_id_is_item(int id) +{ + dumb_ptr<block_list> bl = map_id2bl(id); + return bl ? bl->is_item() : nullptr; +} +inline +dumb_ptr<invocation> map_id_is_spell(int id) +{ + dumb_ptr<block_list> bl = map_id2bl(id); + return bl ? bl->is_spell() : nullptr; +} + + int map_mapname2mapid(const char *); int map_mapname2ipport(const char *, struct in_addr *, int *); int map_setipport(const char *name, struct in_addr ip, int port); -void map_addiddb(struct block_list *); -void map_deliddb(struct block_list *bl); -void map_addnickdb(struct map_session_data *); -int map_scriptcont(struct map_session_data *sd, int id); /* Continues a script either on a spell or on an NPC */ -struct map_session_data *map_nick2sd(const char *); +void map_addiddb(dumb_ptr<block_list>); +void map_deliddb(dumb_ptr<block_list> bl); +void map_addnickdb(dumb_ptr<map_session_data>); +int map_scriptcont(dumb_ptr<map_session_data> sd, int id); /* Continues a script either on a spell or on an NPC */ +dumb_ptr<map_session_data> map_nick2sd(const char *); int compare_item(struct item *a, struct item *b); -struct map_session_data *map_get_first_session(void); -struct map_session_data *map_get_last_session(void); -struct map_session_data *map_get_next_session( - struct map_session_data *current); -struct map_session_data *map_get_prev_session( - struct map_session_data *current); +dumb_ptr<map_session_data> map_get_first_session(void); +dumb_ptr<map_session_data> map_get_last_session(void); +dumb_ptr<map_session_data> map_get_next_session( + dumb_ptr<map_session_data> current); +dumb_ptr<map_session_data> map_get_prev_session( + dumb_ptr<map_session_data> current); // gat関連 MapCell map_getcell(int, int, int); @@ -581,11 +695,35 @@ void map_setcell(int, int, int, MapCell); // その他 bool map_check_dir(DIR s_dir, DIR t_dir); -DIR map_calc_dir(struct block_list *src, int x, int y); +DIR map_calc_dir(dumb_ptr<block_list> src, int x, int y); // path.cより int path_search(struct walkpath_data *, int, int, int, int, int, int); std::pair<uint16_t, uint16_t> map_randfreecell(int m, uint16_t x, uint16_t y, uint16_t w, uint16_t h); +inline dumb_ptr<map_session_data> block_list::as_player() { return dumb_ptr<map_session_data>(static_cast<map_session_data *>(this)) ; } +inline dumb_ptr<npc_data> block_list::as_npc() { return dumb_ptr<npc_data>(static_cast<npc_data *>(this)) ; } +inline dumb_ptr<mob_data> block_list::as_mob() { return dumb_ptr<mob_data>(static_cast<mob_data *>(this)) ; } +inline dumb_ptr<flooritem_data> block_list::as_item() { return dumb_ptr<flooritem_data>(static_cast<flooritem_data *>(this)) ; } +//inline dumb_ptr<invocation> block_list::as_spell() { return dumb_ptr<invocation>(static_cast<invocation *>(this)) ; } + +inline dumb_ptr<map_session_data> block_list::is_player() { return bl_type == BL::PC ? as_player() : nullptr; } +inline dumb_ptr<npc_data> block_list::is_npc() { return bl_type == BL::NPC ? as_npc() : nullptr; } +inline dumb_ptr<mob_data> block_list::is_mob() { return bl_type == BL::MOB ? as_mob() : nullptr; } +inline dumb_ptr<flooritem_data> block_list::is_item() { return bl_type == BL::ITEM ? as_item() : nullptr; } +//inline dumb_ptr<invocation> block_list::is_spell() { return bl_type == BL::SPELL ? as_spell() : nullptr; } + +// struct invocation is defined in another header + +inline dumb_ptr<npc_data_script> npc_data::as_script() { return dumb_ptr<npc_data_script>(static_cast<npc_data_script *>(this)) ; } +inline dumb_ptr<npc_data_shop> npc_data::as_shop() { return dumb_ptr<npc_data_shop>(static_cast<npc_data_shop *>(this)) ; } +inline dumb_ptr<npc_data_warp> npc_data::as_warp() { return dumb_ptr<npc_data_warp>(static_cast<npc_data_warp *>(this)) ; } +inline dumb_ptr<npc_data_message> npc_data::as_message() { return dumb_ptr<npc_data_message>(static_cast<npc_data_message *>(this)) ; } + +inline dumb_ptr<npc_data_script> npc_data::is_script() { return npc_subtype == NpcSubtype::SCRIPT ? as_script() : nullptr ; } +inline dumb_ptr<npc_data_shop> npc_data::is_shop() { return npc_subtype == NpcSubtype::SHOP ? as_shop() : nullptr ; } +inline dumb_ptr<npc_data_warp> npc_data::is_warp() { return npc_subtype == NpcSubtype::WARP ? as_warp() : nullptr ; } +inline dumb_ptr<npc_data_message> npc_data::is_message() { return npc_subtype == NpcSubtype::MESSAGE ? as_message() : nullptr ; } + #endif // MAP_HPP diff --git a/src/map/map.t.hpp b/src/map/map.t.hpp index 172572f..d7b86ec 100644 --- a/src/map/map.t.hpp +++ b/src/map/map.t.hpp @@ -79,7 +79,6 @@ enum class NpcSubtype : uint8_t WARP, SHOP, SCRIPT, - MONS, MESSAGE, }; diff --git a/src/map/mob.cpp b/src/map/mob.cpp index be9a090..828bca5 100644 --- a/src/map/mob.cpp +++ b/src/map/mob.cpp @@ -45,7 +45,7 @@ int mob_makedummymobdb(int); static void mob_timer(TimerData *, tick_t, int, unsigned char); static -int mobskill_use_id(struct mob_data *md, struct block_list *target, +int mobskill_use_id(dumb_ptr<mob_data> md, dumb_ptr<block_list> target, int skill_idx); /*========================================== @@ -82,14 +82,14 @@ int mobdb_checkid(const int id) } static -void mob_init(struct mob_data *md); +void mob_init(dumb_ptr<mob_data> md); /*========================================== * The minimum data set for MOB spawning *------------------------------------------ */ static -int mob_spawn_dataset(struct mob_data *md, const char *mobname, int mob_class) +int mob_spawn_dataset(dumb_ptr<mob_data> md, const char *mobname, int mob_class) { nullpo_ret(md); @@ -191,7 +191,7 @@ earray<int, mob_stat, mob_stat::XP_BONUS> mutation_base //= */ // intensity: positive: strengthen, negative: weaken. 256 = 100%. static -void mob_mutate(struct mob_data *md, mob_stat stat, int intensity) +void mob_mutate(dumb_ptr<mob_data> md, mob_stat stat, int intensity) { int old_stat; int new_stat; @@ -302,7 +302,7 @@ int mob_gen_exp(struct mob_db *mob) } static -void mob_init(struct mob_data *md) +void mob_init(dumb_ptr<mob_data> md) { int i; const int mob_class = md->mob_class; @@ -366,11 +366,11 @@ void mob_init(struct mob_data *md) * The MOB appearance for one time (for scripts) *------------------------------------------ */ -int mob_once_spawn(struct map_session_data *sd, const char *mapname, +int mob_once_spawn(dumb_ptr<map_session_data> sd, const char *mapname, int x, int y, const char *mobname, int mob_class, int amount, const char *event) { - struct mob_data *md = NULL; + dumb_ptr<mob_data> md = NULL; int m, count, r = mob_class; if (sd && strcmp(mapname, "this") == 0) @@ -395,7 +395,7 @@ int mob_once_spawn(struct map_session_data *sd, const char *mapname, for (count = 0; count < amount; count++) { - md = (struct mob_data *) calloc(1, sizeof(struct mob_data)); + md.new_(); if (bool(mob_db[mob_class].mode & MobMode::LOOTER)) md->lootitem = (struct item *) calloc(LOOTITEM_SIZE, sizeof(struct item)); @@ -430,7 +430,7 @@ int mob_once_spawn(struct map_session_data *sd, const char *mapname, * The MOB appearance for one time (& area specification for scripts) *------------------------------------------ */ -int mob_once_spawn_area(struct map_session_data *sd, const char *mapname, +int mob_once_spawn_area(dumb_ptr<map_session_data> sd, const char *mapname, int x0, int y0, int x1, int y1, const char *mobname, int mob_class, int amount, const char *event) @@ -533,7 +533,7 @@ int mob_get_equip(int mob_class) // mob equip [Valaris] *------------------------------------------ */ static -int mob_can_move(struct mob_data *md) +int mob_can_move(dumb_ptr<mob_data> md) { nullpo_ret(md); @@ -549,7 +549,7 @@ int mob_can_move(struct mob_data *md) *------------------------------------------ */ static -interval_t calc_next_walk_step(struct mob_data *md) +interval_t calc_next_walk_step(dumb_ptr<mob_data> md) { nullpo_retr(interval_t::zero(), md); @@ -561,14 +561,14 @@ interval_t calc_next_walk_step(struct mob_data *md) } static -int mob_walktoxy_sub(struct mob_data *md); +int mob_walktoxy_sub(dumb_ptr<mob_data> md); /*========================================== * Mob Walk processing *------------------------------------------ */ static -int mob_walk(struct mob_data *md, tick_t tick, unsigned char data) +int mob_walk(dumb_ptr<mob_data> md, tick_t tick, unsigned char data) { int moveblock; int x, y, dx, dy; @@ -662,11 +662,11 @@ int mob_walk(struct mob_data *md, tick_t tick, unsigned char data) *------------------------------------------ */ static -int mob_check_attack(struct mob_data *md) +int mob_check_attack(dumb_ptr<mob_data> md) { - struct block_list *tbl = NULL; - struct map_session_data *tsd = NULL; - struct mob_data *tmd = NULL; + dumb_ptr<block_list> tbl = NULL; + dumb_ptr<map_session_data> tsd = NULL; + dumb_ptr<mob_data> tmd = NULL; MobMode mode; int range; @@ -691,9 +691,9 @@ int mob_check_attack(struct mob_data *md) } if (tbl->bl_type == BL::PC) - tsd = (struct map_session_data *) tbl; + tsd = tbl->as_player(); else if (tbl->bl_type == BL::MOB) - tmd = (struct mob_data *) tbl; + tmd = tbl->as_mob(); else return 0; @@ -752,8 +752,8 @@ 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, tick_t tick) +void mob_ancillary_attack(dumb_ptr<block_list> bl, + dumb_ptr<block_list> mdbl, dumb_ptr<block_list> tbl, tick_t tick) { if (bl != tbl) battle_weapon_attack(mdbl, bl, tick); @@ -764,9 +764,9 @@ void mob_ancillary_attack(struct block_list *bl, *------------------------------------------ */ static -int mob_attack(struct mob_data *md, tick_t tick) +int mob_attack(dumb_ptr<mob_data> md, tick_t tick) { - struct block_list *tbl = NULL; + dumb_ptr<block_list> tbl = NULL; nullpo_ret(md); @@ -810,7 +810,7 @@ int mob_attack(struct mob_data *md, tick_t tick) *------------------------------------------ */ static -void mob_stopattacked(struct map_session_data *sd, int id) +void mob_stopattacked(dumb_ptr<map_session_data> sd, int id) { nullpo_retv(sd); @@ -823,7 +823,7 @@ void mob_stopattacked(struct map_session_data *sd, int id) *------------------------------------------ */ static -int mob_changestate(struct mob_data *md, MS state, bool type) +int mob_changestate(dumb_ptr<mob_data> md, MS state, bool type) { nullpo_ret(md); @@ -896,8 +896,8 @@ int mob_changestate(struct mob_data *md, MS state, bool type) static void mob_timer(TimerData *, tick_t tick, int id, unsigned char data) { - struct mob_data *md; - struct block_list *bl; + dumb_ptr<mob_data> md; + dumb_ptr<block_list> bl; bl = map_id2bl(id); if (bl == NULL) { //攻撃してきた敵がもういないのは正常のようだ @@ -907,7 +907,7 @@ void mob_timer(TimerData *, tick_t tick, int id, unsigned char data) if (bl->bl_type == BL::NUL || bl->bl_type != BL::MOB) return; - md = (struct mob_data *) bl; + md = bl->as_mob(); if (md->bl_prev == NULL || md->state.state == MS::DEAD) return; @@ -935,7 +935,7 @@ void mob_timer(TimerData *, tick_t tick, int id, unsigned char data) *------------------------------------------ */ static -int mob_walktoxy_sub(struct mob_data *md) +int mob_walktoxy_sub(dumb_ptr<mob_data> md) { struct walkpath_data wpd; @@ -958,7 +958,7 @@ int mob_walktoxy_sub(struct mob_data *md) *------------------------------------------ */ static -int mob_walktoxy(struct mob_data *md, int x, int y, int easy) +int mob_walktoxy(dumb_ptr<mob_data> md, int x, int y, int easy) { struct walkpath_data wpd; @@ -1000,8 +1000,8 @@ void mob_delayspawn(TimerData *, tick_t, int m) static int mob_setdelayspawn(int id) { - struct mob_data *md; - struct block_list *bl; + dumb_ptr<mob_data> md; + dumb_ptr<block_list> bl; if ((bl = map_id2bl(id)) == NULL) return -1; @@ -1009,7 +1009,7 @@ int mob_setdelayspawn(int id) if (!bl || bl->bl_type == BL::NUL || bl->bl_type != BL::MOB) return -1; - md = (struct mob_data *) bl; + md = bl->as_mob(); nullpo_retr(-1, md); if (!md || md->bl_type != BL::MOB) @@ -1050,8 +1050,8 @@ int mob_spawn(int id) { int x = 0, y = 0; tick_t tick = gettick(); - struct mob_data *md; - struct block_list *bl; + dumb_ptr<mob_data> md; + dumb_ptr<block_list> bl; bl = map_id2bl(id); nullpo_retr(-1, bl); @@ -1059,7 +1059,7 @@ int mob_spawn(int id) if (!bl || bl->bl_type == BL::NUL || bl->bl_type != BL::MOB) return -1; - md = (struct mob_data *) bl; + md = bl->as_mob(); nullpo_retr(-1, md); if (!md || md->bl_type == BL::NUL || md->bl_type != BL::MOB) @@ -1186,7 +1186,7 @@ int distance(int x0, int y0, int x1, int y1) * The stop of MOB's attack *------------------------------------------ */ -int mob_stopattack(struct mob_data *md) +int mob_stopattack(dumb_ptr<mob_data> md) { md->target_id = 0; md->state.attackable = false; @@ -1198,7 +1198,7 @@ int mob_stopattack(struct mob_data *md) * The stop of MOB's walking *------------------------------------------ */ -int mob_stop_walking(struct mob_data *md, int type) +int mob_stop_walking(dumb_ptr<mob_data> md, int type) { nullpo_ret(md); @@ -1247,7 +1247,7 @@ int mob_stop_walking(struct mob_data *md, int type) *------------------------------------------ */ static -int mob_can_reach(struct mob_data *md, struct block_list *bl, int range) +int mob_can_reach(dumb_ptr<mob_data> md, dumb_ptr<block_list> bl, int range) { int dx, dy; struct walkpath_data wpd; @@ -1259,10 +1259,10 @@ int mob_can_reach(struct mob_data *md, struct block_list *bl, int range) dx = abs(bl->bl_x - md->bl_x); dy = abs(bl->bl_y - md->bl_y); - if (bl && bl->bl_type == BL::PC && battle_config.monsters_ignore_gm == 1) + if (bl->bl_type == BL::PC && battle_config.monsters_ignore_gm == 1) { // option to have monsters ignore GMs [Valaris] - struct map_session_data *sd; - if ((sd = (struct map_session_data *) bl) != NULL && pc_isGM(sd)) + dumb_ptr<map_session_data> sd = bl->as_player(); + if (pc_isGM(sd)) return 0; } @@ -1304,9 +1304,9 @@ int mob_can_reach(struct mob_data *md, struct block_list *bl, int range) * Determination for an attack of a monster *------------------------------------------ */ -int mob_target(struct mob_data *md, struct block_list *bl, int dist) +int mob_target(dumb_ptr<mob_data> md, dumb_ptr<block_list> bl, int dist) { - struct map_session_data *sd; + dumb_ptr<map_session_data> sd; eptr<struct status_change, StatusChange> sc_data; MobMode mode; @@ -1344,7 +1344,7 @@ int mob_target(struct mob_data *md, struct block_list *bl, int dist) { if (bl->bl_type == BL::PC) { - sd = (struct map_session_data *) bl; + sd = bl->as_player(); nullpo_ret(sd); if (sd->invincible_timer || pc_isinvisible(sd)) return 0; @@ -1370,11 +1370,11 @@ int mob_target(struct mob_data *md, struct block_list *bl, int dist) *------------------------------------------ */ static -void mob_ai_sub_hard_activesearch(struct block_list *bl, - struct mob_data *smd, int *pcc) +void mob_ai_sub_hard_activesearch(dumb_ptr<block_list> bl, + dumb_ptr<mob_data> smd, int *pcc) { - struct map_session_data *tsd = NULL; - struct mob_data *tmd = NULL; + dumb_ptr<map_session_data> tsd = NULL; + dumb_ptr<mob_data> tmd = NULL; MobMode mode; int dist; @@ -1383,9 +1383,9 @@ void mob_ai_sub_hard_activesearch(struct block_list *bl, nullpo_retv(pcc); if (bl->bl_type == BL::PC) - tsd = (struct map_session_data *) bl; + tsd = bl->as_player(); else if (bl->bl_type == BL::MOB) - tmd = (struct mob_data *) bl; + tmd = bl->as_mob(); else return; @@ -1452,7 +1452,7 @@ void mob_ai_sub_hard_activesearch(struct block_list *bl, *------------------------------------------ */ static -void mob_ai_sub_hard_lootsearch(struct block_list *bl, struct mob_data *md, int *itc) +void mob_ai_sub_hard_lootsearch(dumb_ptr<block_list> bl, dumb_ptr<mob_data> md, int *itc) { MobMode mode; int dist; @@ -1495,12 +1495,12 @@ void mob_ai_sub_hard_lootsearch(struct block_list *bl, struct mob_data *md, int *------------------------------------------ */ static -void mob_ai_sub_hard_linksearch(struct block_list *bl, struct mob_data *md, struct block_list *target) +void mob_ai_sub_hard_linksearch(dumb_ptr<block_list> bl, dumb_ptr<mob_data> md, dumb_ptr<block_list> target) { - struct mob_data *tmd; + dumb_ptr<mob_data> tmd; nullpo_retv(bl); - tmd = (struct mob_data *) bl; + tmd = bl->as_mob(); nullpo_retv(md); nullpo_retv(target); @@ -1527,17 +1527,17 @@ 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, tick_t tick) +int mob_ai_sub_hard_slavemob(dumb_ptr<mob_data> md, tick_t tick) { - struct mob_data *mmd = NULL; - struct block_list *bl; + dumb_ptr<mob_data> mmd = NULL; + dumb_ptr<block_list> bl; MobMode mode; int old_dist; nullpo_ret(md); if ((bl = map_id2bl(md->master_id)) != NULL) - mmd = (struct mob_data *) bl; + mmd = bl->as_mob(); mode = mob_db[md->mob_class].mode; @@ -1630,7 +1630,7 @@ int mob_ai_sub_hard_slavemob(struct mob_data *md, tick_t tick) if ((mmd->target_id > 0 && mmd->state.attackable) && (!md->target_id || !md->state.attackable)) { - struct map_session_data *sd = map_id2sd(mmd->target_id); + dumb_ptr<map_session_data> sd = map_id2sd(mmd->target_id); if (sd != NULL && !pc_isdead(sd) && !sd->invincible_timer && !pc_isinvisible(sd)) { @@ -1659,7 +1659,7 @@ int mob_ai_sub_hard_slavemob(struct mob_data *md, tick_t tick) *------------------------------------------ */ static -int mob_unlocktarget(struct mob_data *md, tick_t tick) +int mob_unlocktarget(dumb_ptr<mob_data> md, tick_t tick) { nullpo_ret(md); @@ -1675,7 +1675,7 @@ int mob_unlocktarget(struct mob_data *md, tick_t tick) *------------------------------------------ */ static -int mob_randomwalk(struct mob_data *md, tick_t tick) +int mob_randomwalk(dumb_ptr<mob_data> md, tick_t tick) { const int retrycount = 20; @@ -1732,18 +1732,18 @@ int mob_randomwalk(struct mob_data *md, tick_t tick) *------------------------------------------ */ static -void mob_ai_sub_hard(struct block_list *bl, tick_t tick) +void mob_ai_sub_hard(dumb_ptr<block_list> bl, tick_t tick) { - struct mob_data *md, *tmd = NULL; - struct map_session_data *tsd = NULL; - struct block_list *tbl = NULL; - struct flooritem_data *fitem; + dumb_ptr<mob_data> md, tmd = NULL; + dumb_ptr<map_session_data> tsd = NULL; + dumb_ptr<block_list> tbl = NULL; + dumb_ptr<flooritem_data> fitem; int i, dx, dy, ret, dist; int attack_type = 0; MobMode mode; nullpo_retv(bl); - md = (struct mob_data *) bl; + md = bl->as_mob(); if (tick < md->last_thinktime + MIN_MOBTHINKTIME) return; @@ -1773,7 +1773,7 @@ void mob_ai_sub_hard(struct block_list *bl, tick_t tick) if (md->attacked_id > 0 && bool(mode & MobMode::ASSIST)) { // Link monster - struct map_session_data *asd = map_id2sd(md->attacked_id); + dumb_ptr<map_session_data> asd = map_id2sd(md->attacked_id); if (asd) { if (!asd->invincible_timer && !pc_isinvisible(asd)) @@ -1790,12 +1790,12 @@ void mob_ai_sub_hard(struct block_list *bl, tick_t tick) && (!md->target_id || !md->state.attackable || (bool(mode & MobMode::AGGRESSIVE) && random_::chance({25, 100})))) { - struct block_list *abl = map_id2bl(md->attacked_id); - struct map_session_data *asd = NULL; + dumb_ptr<block_list> abl = map_id2bl(md->attacked_id); + dumb_ptr<map_session_data> asd = NULL; if (abl) { if (abl->bl_type == BL::PC) - asd = (struct map_session_data *) abl; + asd = abl->as_player(); if (asd == NULL || md->bl_m != abl->bl_m || abl->bl_prev == NULL || asd->invincible_timer || pc_isinvisible(asd) || (dist = @@ -1858,9 +1858,9 @@ void mob_ai_sub_hard(struct block_list *bl, tick_t tick) if ((tbl = map_id2bl(md->target_id))) { if (tbl->bl_type == BL::PC) - tsd = (struct map_session_data *) tbl; + tsd = tbl->as_player(); else if (tbl->bl_type == BL::MOB) - tmd = (struct mob_data *) tbl; + tmd = tbl->as_mob(); if (tsd || tmd) { if (tbl->bl_m != md->bl_m || tbl->bl_prev == NULL @@ -1990,7 +1990,7 @@ void mob_ai_sub_hard(struct block_list *bl, tick_t tick) return; // 攻撃中 if (md->state.state == MS::WALK) mob_stop_walking(md, 1); // 歩行中なら停止 - fitem = (struct flooritem_data *) tbl; + fitem = tbl->as_item(); if (md->lootitem_count < LOOTITEM_SIZE) memcpy(&md->lootitem[md->lootitem_count++], &fitem->item_data, sizeof(md->lootitem[0])); @@ -2059,7 +2059,7 @@ void mob_ai_sub_hard(struct block_list *bl, tick_t tick) *------------------------------------------ */ static -void mob_ai_sub_foreachclient(struct map_session_data *sd, tick_t tick) +void mob_ai_sub_foreachclient(dumb_ptr<map_session_data> sd, tick_t tick) { nullpo_retv(sd); @@ -2083,14 +2083,14 @@ void mob_ai_hard(TimerData *, tick_t tick) *------------------------------------------ */ static -void mob_ai_sub_lazy(struct block_list *bl, tick_t tick) +void mob_ai_sub_lazy(dumb_ptr<block_list> bl, tick_t tick) { nullpo_retv(bl); if (bl->bl_type != BL::MOB) return; - struct mob_data *md = (struct mob_data *)bl; + dumb_ptr<mob_data> md = bl->as_mob(); if (tick < md->last_thinktime + MIN_MOBTHINKTIME * 10) return; @@ -2161,14 +2161,14 @@ struct delay_item_drop { int m, x, y; int nameid, amount; - struct map_session_data *first_sd, *second_sd, *third_sd; + dumb_ptr<map_session_data> first_sd, second_sd, third_sd; }; struct delay_item_drop2 { int m, x, y; struct item item_data; - struct map_session_data *first_sd, *second_sd, *third_sd; + dumb_ptr<map_session_data> first_sd, second_sd, third_sd; }; /*========================================== @@ -2250,7 +2250,7 @@ void mob_delay_item_drop2(TimerData *, tick_t, struct delay_item_drop2 *ditem) * mob data is erased. *------------------------------------------ */ -int mob_delete(struct mob_data *md) +int mob_delete(dumb_ptr<mob_data> md) { nullpo_retr(1, md); @@ -2264,7 +2264,7 @@ int mob_delete(struct mob_data *md) return 0; } -int mob_catch_delete(struct mob_data *md, BeingRemoveWhy type) +int mob_catch_delete(dumb_ptr<mob_data> md, BeingRemoveWhy type) { nullpo_retr(1, md); @@ -2279,12 +2279,12 @@ int mob_catch_delete(struct mob_data *md, BeingRemoveWhy type) void mob_timer_delete(TimerData *, tick_t, int id) { - struct block_list *bl = map_id2bl(id); - struct mob_data *md; + dumb_ptr<block_list> bl = map_id2bl(id); + dumb_ptr<mob_data> md; nullpo_retv(bl); - md = (struct mob_data *) bl; + md = bl->as_mob(); mob_catch_delete(md, BeingRemoveWhy::WARPED); } @@ -2293,12 +2293,12 @@ void mob_timer_delete(TimerData *, tick_t, int id) *------------------------------------------ */ static -void mob_deleteslave_sub(struct block_list *bl, int id) +void mob_deleteslave_sub(dumb_ptr<block_list> bl, int id) { - struct mob_data *md; + dumb_ptr<mob_data> md; nullpo_retv(bl); - md = (struct mob_data *) bl; + md = bl->as_mob(); if (md->master_id > 0 && md->master_id == id) mob_damage(NULL, md, md->hp, 1); @@ -2308,7 +2308,7 @@ void mob_deleteslave_sub(struct block_list *bl, int id) * *------------------------------------------ */ -int mob_deleteslave(struct mob_data *md) +int mob_deleteslave(dumb_ptr<mob_data> md) { nullpo_ret(md); @@ -2330,11 +2330,11 @@ double damage_bonus_factor[DAMAGE_BONUS_COUNT + 1] = * It is the damage of sd to damage to md. *------------------------------------------ */ -int mob_damage(struct block_list *src, struct mob_data *md, int damage, +int mob_damage(dumb_ptr<block_list> src, dumb_ptr<mob_data> md, int damage, int type) { int count, minpos, mindmg; - struct map_session_data *sd = NULL, *tmpsd[DAMAGELOG_SIZE]; + dumb_ptr<map_session_data> sd = NULL, tmpsd[DAMAGELOG_SIZE]; struct { struct party *p; @@ -2343,8 +2343,7 @@ int mob_damage(struct block_list *src, struct mob_data *md, int damage, int pnum = 0; int mvp_damage, max_hp; tick_t tick = gettick(); - struct map_session_data *mvp_sd = NULL, *second_sd = NULL, *third_sd = - NULL; + dumb_ptr<map_session_data> mvp_sd = NULL, second_sd = NULL, third_sd = NULL; double tdmg; nullpo_ret(md); //srcはNULLで呼ばれる場合もあるので、他でチェック @@ -2363,7 +2362,7 @@ int mob_damage(struct block_list *src, struct mob_data *md, int damage, if (src && src->bl_type == BL::PC) { - sd = (struct map_session_data *) src; + sd = src->as_player(); mvp_sd = sd; } @@ -2435,13 +2434,13 @@ int mob_damage(struct block_list *src, struct mob_data *md, int damage, md->attacked_id = sd->bl_id; } if (src && src->bl_type == BL::MOB - && ((struct mob_data *) src)->state.special_mob_ai) + && src->as_mob()->state.special_mob_ai) { - struct mob_data *md2 = (struct mob_data *) src; - struct block_list *master_bl = map_id2bl(md2->master_id); + dumb_ptr<mob_data> md2 = src->as_mob(); + dumb_ptr<block_list> master_bl = map_id2bl(md2->master_id); if (master_bl && master_bl->bl_type == BL::PC) { - MAP_LOG_PC(((struct map_session_data *) master_bl), + MAP_LOG_PC(master_bl->as_player(), "MOB-TO-MOB-DMG FROM MOB%d %d TO MOB%d %d FOR %d", md2->bl_id, md2->mob_class, md->bl_id, md->mob_class, damage); @@ -2501,7 +2500,7 @@ int mob_damage(struct block_list *src, struct mob_data *md, int damage, max_hp = battle_get_max_hp(md); if (src && src->bl_type == BL::MOB) - mob_unlocktarget((struct mob_data *) src, tick); + mob_unlocktarget(src->as_mob(), tick); // map外に消えた人は計算から除くので // overkill分は無いけどsumはmax_hpとは違う @@ -2697,7 +2696,7 @@ int mob_damage(struct block_list *src, struct mob_data *md, int damage, { if (!session[i]) continue; - map_session_data *tmp_sd = static_cast<map_session_data *>(session[i]->session_data.get()); + dumb_ptr<map_session_data> tmp_sd = dumb_ptr<map_session_data>(static_cast<map_session_data *>(session[i]->session_data.get())); if (tmp_sd && tmp_sd->state.auth) { if (md->bl_m == tmp_sd->bl_m) @@ -2725,7 +2724,7 @@ int mob_damage(struct block_list *src, struct mob_data *md, int damage, * mob回復 *------------------------------------------ */ -int mob_heal(struct mob_data *md, int heal) +int mob_heal(dumb_ptr<mob_data> md, int heal) { int max_hp = battle_get_max_hp(md); @@ -2743,9 +2742,9 @@ int mob_heal(struct mob_data *md, int heal) *------------------------------------------ */ static -void mob_warpslave_sub(struct block_list *bl, int id, int x, int y) +void mob_warpslave_sub(dumb_ptr<block_list> bl, int id, int x, int y) { - struct mob_data *md = (struct mob_data *) bl; + dumb_ptr<mob_data> md = bl->as_mob(); if (md->master_id == id) { @@ -2758,7 +2757,7 @@ void mob_warpslave_sub(struct block_list *bl, int id, int x, int y) *------------------------------------------ */ static -int mob_warpslave(struct mob_data *md, int x, int y) +int mob_warpslave(dumb_ptr<mob_data> md, int x, int y) { //PRINTF("warp slave\n"); map_foreachinarea(std::bind(mob_warpslave_sub, ph::_1, md->bl_id, md->bl_x, md->bl_y), @@ -2771,7 +2770,7 @@ int mob_warpslave(struct mob_data *md, int x, int y) * mobワープ *------------------------------------------ */ -int mob_warp(struct mob_data *md, int m, int x, int y, BeingRemoveWhy type) +int mob_warp(dumb_ptr<mob_data> md, int m, int x, int y, BeingRemoveWhy type) { int i = 0, xs = 0, ys = 0, bx = x, by = y; @@ -2856,12 +2855,12 @@ int mob_warp(struct mob_data *md, int m, int x, int y, BeingRemoveWhy type) *------------------------------------------ */ static -void mob_countslave_sub(struct block_list *bl, int id, int *c) +void mob_countslave_sub(dumb_ptr<block_list> bl, int id, int *c) { - struct mob_data *md; + dumb_ptr<mob_data> md; nullpo_retv(bl); - md = (struct mob_data *) bl; + md = bl->as_mob(); if (md->master_id == id) (*c)++; @@ -2872,7 +2871,7 @@ void mob_countslave_sub(struct block_list *bl, int id, int *c) *------------------------------------------ */ static -int mob_countslave(struct mob_data *md) +int mob_countslave(dumb_ptr<mob_data> md) { int c = 0; @@ -2888,9 +2887,9 @@ int mob_countslave(struct mob_data *md) * 手下MOB召喚 *------------------------------------------ */ -int mob_summonslave(struct mob_data *md2, int *value, int amount, int flag) +int mob_summonslave(dumb_ptr<mob_data> md2, int *value, int amount, int flag) { - struct mob_data *md; + dumb_ptr<mob_data> md; int bx, by, m, count = 0, mob_class, k, a = amount; nullpo_ret(md2); @@ -2916,7 +2915,7 @@ int mob_summonslave(struct mob_data *md2, int *value, int amount, int flag) for (; amount > 0; amount--) { int x = 0, y = 0, i = 0; - md = (struct mob_data *) calloc(1, sizeof(struct mob_data)); + md.new_(); if (bool(mob_db[mob_class].mode & MobMode::LOOTER)) md->lootitem = (struct item *) calloc(LOOTITEM_SIZE, sizeof(struct item)); @@ -2970,8 +2969,8 @@ int mob_summonslave(struct mob_data *md2, int *value, int amount, int flag) *------------------------------------------ */ static -void mob_counttargeted_sub(struct block_list *bl, - int id, int *c, struct block_list *src, ATK target_lv) +void mob_counttargeted_sub(dumb_ptr<block_list> bl, + int id, int *c, dumb_ptr<block_list> src, ATK target_lv) { nullpo_retv(bl); nullpo_retv(c); @@ -2980,14 +2979,14 @@ void mob_counttargeted_sub(struct block_list *bl, return; if (bl->bl_type == BL::PC) { - struct map_session_data *sd = (struct map_session_data *) bl; + dumb_ptr<map_session_data> sd = bl->as_player(); if (sd && sd->attacktarget == id && sd->attacktimer && sd->attacktarget_lv >= target_lv) (*c)++; } else if (bl->bl_type == BL::MOB) { - struct mob_data *md = (struct mob_data *) bl; + dumb_ptr<mob_data> md = bl->as_mob(); if (md && md->target_id == id && md->timer && md->state.state == MS::ATTACK && md->target_lv >= target_lv) (*c)++; @@ -2998,7 +2997,7 @@ void mob_counttargeted_sub(struct block_list *bl, * 自分をロックしているPCの数を数える *------------------------------------------ */ -int mob_counttargeted(struct mob_data *md, struct block_list *src, +int mob_counttargeted(dumb_ptr<mob_data> md, dumb_ptr<block_list> src, ATK target_lv) { int c = 0; @@ -3022,14 +3021,14 @@ int mob_counttargeted(struct mob_data *md, struct block_list *src, */ void mobskill_castend_id(TimerData *, tick_t tick, int id) { - struct mob_data *md = NULL; - struct block_list *bl; - struct block_list *mbl; + dumb_ptr<mob_data> md = NULL; + dumb_ptr<block_list> bl; + dumb_ptr<block_list> mbl; int range; if ((mbl = map_id2bl(id)) == NULL) //詠唱したMobがもういないというのは良くある正常処理 return; - if ((md = (struct mob_data *) mbl) == NULL) + if ((md = mbl->as_mob()) == NULL) { PRINTF("mobskill_castend_id nullpo mbl->bl_id:%d\n", mbl->bl_id); return; @@ -3089,15 +3088,15 @@ void mobskill_castend_id(TimerData *, tick_t tick, int id) */ void mobskill_castend_pos(TimerData *, tick_t tick, int id) { - struct mob_data *md = NULL; - struct block_list *bl; + dumb_ptr<mob_data> md = NULL; + dumb_ptr<block_list> bl; int range; //mobskill_castend_id同様詠唱したMobが詠唱完了時にもういないというのはありそうなのでnullpoから除外 if ((bl = map_id2bl(id)) == NULL) return; - md = (struct mob_data *) bl; + md = bl->as_mob(); nullpo_retv(md); if (md->bl_type != BL::MOB || md->bl_prev == NULL) @@ -3123,7 +3122,7 @@ void mobskill_castend_pos(TimerData *, tick_t tick, int id) * Skill use (an aria start, ID specification) *------------------------------------------ */ -int mobskill_use_id(struct mob_data *md, struct block_list *target, +int mobskill_use_id(dumb_ptr<mob_data> md, dumb_ptr<block_list> target, int skill_idx) { int range; @@ -3199,7 +3198,7 @@ int mobskill_use_id(struct mob_data *md, struct block_list *target, *------------------------------------------ */ static -int mobskill_use_pos(struct mob_data *md, +int mobskill_use_pos(dumb_ptr<mob_data> md, int skill_x, int skill_y, int skill_idx) { int range; @@ -3228,7 +3227,7 @@ int mobskill_use_pos(struct mob_data *md, range = skill_get_range(skill_id, skill_lv); if (range < 0) range = battle_get_range(md) - (range + 1); - if (!battle_check_range(md, &bl, range)) + if (!battle_check_range(md, dumb_ptr<block_list>(&bl), range)) return 0; // delay=skill_delayfix(sd, skill_get_delay( skill_id,skill_lv) ); @@ -3270,11 +3269,11 @@ int mobskill_use_pos(struct mob_data *md, * Skill use judging *------------------------------------------ */ -int mobskill_use(struct mob_data *md, tick_t tick, +int mobskill_use(dumb_ptr<mob_data> md, tick_t tick, MobSkillCondition event) { struct mob_skill *ms; -// struct block_list *target=NULL; +// dumb_ptr<block_list> target=NULL; int max_hp; nullpo_ret(md); @@ -3332,14 +3331,13 @@ int mobskill_use(struct mob_data *md, tick_t tick, if (skill_get_inf(ms[ii].skill_id) & 2) { // 場所指定 - struct block_list *bl = NULL; + dumb_ptr<block_list> bl = NULL; int x = 0, y = 0; { - { - bl = ms[ii].target == MobSkillTarget::MST_TARGET - ? map_id2bl(md->target_id) - : md; - } + if (ms[ii].target == MobSkillTarget::MST_TARGET) + bl = map_id2bl(md->target_id); + else + bl = md; if (bl) { @@ -3355,10 +3353,11 @@ int mobskill_use(struct mob_data *md, tick_t tick, else { { - struct block_list *bl = NULL; - bl = (ms[ii].target == MobSkillTarget::MST_TARGET) - ? map_id2bl(md->target_id) - : md; + dumb_ptr<block_list> bl = NULL; + if (ms[ii].target == MobSkillTarget::MST_TARGET) + bl = map_id2bl(md->target_id); + else + bl = md; if (bl && !mobskill_use_id(md, bl, ii)) return 0; } @@ -3376,7 +3375,7 @@ int mobskill_use(struct mob_data *md, tick_t tick, * Skill use event processing *------------------------------------------ */ -int mobskill_event(struct mob_data *md, BF flag) +int mobskill_event(dumb_ptr<mob_data> md, BF flag) { nullpo_ret(md); diff --git a/src/map/mob.hpp b/src/map/mob.hpp index 16715c4..7421fca 100644 --- a/src/map/mob.hpp +++ b/src/map/mob.hpp @@ -58,19 +58,19 @@ extern struct mob_db mob_db[]; int mobdb_searchname(const char *str); int mobdb_checkid(const int id); -int mob_once_spawn(struct map_session_data *sd, +int mob_once_spawn(dumb_ptr<map_session_data> sd, const char *mapname, int x, int y, const char *mobname, int class_, int amount, const char *event); -int mob_once_spawn_area(struct map_session_data *sd, +int mob_once_spawn_area(dumb_ptr<map_session_data> sd, const char *mapname, int x0, int y0, int x1, int y1, const char *mobname, int class_, int amount, const char *event); -int mob_target(struct mob_data *md, struct block_list *bl, int dist); -int mob_stop_walking(struct mob_data *md, int type); -int mob_stopattack(struct mob_data *); +int mob_target(dumb_ptr<mob_data> md, dumb_ptr<block_list> bl, int dist); +int mob_stop_walking(dumb_ptr<mob_data> md, int type); +int mob_stopattack(dumb_ptr<mob_data>); int mob_spawn(int); -int mob_damage(struct block_list *, struct mob_data *, int, int); -int mob_heal(struct mob_data *, int); +int mob_damage(dumb_ptr<block_list>, dumb_ptr<mob_data>, int, int); +int mob_heal(dumb_ptr<mob_data>, int); int mob_get_sex(int); short mob_get_hair(int); short mob_get_hair_color(int); @@ -83,22 +83,22 @@ short mob_get_clothes_color(int); //player mob dye [Valaris] int mob_get_equip(int); // mob equip [Valaris] int do_init_mob(void); -int mob_delete(struct mob_data *md); -int mob_catch_delete(struct mob_data *md, BeingRemoveWhy type); +int mob_delete(dumb_ptr<mob_data> md); +int mob_catch_delete(dumb_ptr<mob_data> md, BeingRemoveWhy type); void mob_timer_delete(TimerData *, tick_t, int); -int mob_deleteslave(struct mob_data *md); +int mob_deleteslave(dumb_ptr<mob_data> md); -int mob_counttargeted(struct mob_data *md, struct block_list *src, +int mob_counttargeted(dumb_ptr<mob_data> md, dumb_ptr<block_list> src, ATK target_lv); -int mob_warp(struct mob_data *md, int m, int x, int y, BeingRemoveWhy type); +int mob_warp(dumb_ptr<mob_data> md, int m, int x, int y, BeingRemoveWhy type); -int mobskill_use(struct mob_data *md, tick_t tick, MobSkillCondition event); -int mobskill_event(struct mob_data *md, BF flag); +int mobskill_use(dumb_ptr<mob_data> md, tick_t tick, MobSkillCondition event); +int mobskill_event(dumb_ptr<mob_data> md, BF flag); 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); +int mob_summonslave(dumb_ptr<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 f0ea12e..43766e9 100644 --- a/src/map/npc.cpp +++ b/src/map/npc.cpp @@ -43,13 +43,13 @@ int npc_get_new_npc_id(void) struct event_data { - struct npc_data *nd; + dumb_ptr<npc_data_script> nd; int pos; }; static Map<std::string, struct event_data> ev_db; static -DMap<std::string, struct npc_data *> npcname_db; +DMap<std::string, dumb_ptr<npc_data>> npcname_db; static struct tm ev_tm_b; // 時計イベント用 @@ -61,22 +61,26 @@ struct tm ev_tm_b; // 時計イベント用 *------------------------------------------ */ static -void npc_enable_sub(struct block_list *bl, struct npc_data *nd) +void npc_enable_sub(dumb_ptr<block_list> bl, dumb_ptr<npc_data> nd) { - struct map_session_data *sd; + dumb_ptr<map_session_data> sd; char *name = (char *) calloc(50, sizeof(char)); nullpo_retv(bl); - if (bl->bl_type == BL::PC && (sd = (struct map_session_data *) bl)) + if (bl->bl_type == BL::PC) { + sd = bl->as_player(); if (nd->flag & 1) // 無効化されている return; memcpy(name, nd->name, sizeof(nd->name)); if (sd->areanpc_id == nd->bl_id) - return; // TODO fix leak of 'name' + { + free(name); + return; + } sd->areanpc_id = nd->bl_id; npc_event(sd, strcat(name, "::OnTouch"), 0); } @@ -85,7 +89,7 @@ void npc_enable_sub(struct block_list *bl, struct npc_data *nd) int npc_enable(const char *name, bool flag) { - struct npc_data *nd = npcname_db.get(name); + dumb_ptr<npc_data> nd = npcname_db.get(name); if (nd == NULL) return 0; @@ -99,10 +103,18 @@ int npc_enable(const char *name, bool flag) nd->flag |= 1; clif_clearchar(nd, BeingRemoveWhy::GONE); } - if (flag && (nd->u.scr.xs > 0 || nd->u.scr.ys > 0)) + + int xs = 0, ys = 0; + if (dumb_ptr<npc_data_script> nd_ = nd->is_script()) + { + xs = nd_->scr.xs; + ys = nd_->scr.ys; + } + + if (flag && (xs > 0 || ys > 0)) map_foreachinarea(std::bind(npc_enable_sub, ph::_1, nd), - nd->bl_m, nd->bl_x - nd->u.scr.xs, nd->bl_y - nd->u.scr.ys, - nd->bl_x + nd->u.scr.xs, nd->bl_y + nd->u.scr.ys, BL::PC); + nd->bl_m, nd->bl_x - xs, nd->bl_y - ys, + nd->bl_x + xs, nd->bl_y + ys, BL::PC); return 0; } @@ -111,7 +123,7 @@ int npc_enable(const char *name, bool flag) * NPCを名前で探す *------------------------------------------ */ -struct npc_data *npc_name2id(const char *name) +dumb_ptr<npc_data> npc_name2id(const char *name) { return npcname_db.get(name); } @@ -120,7 +132,7 @@ struct npc_data *npc_name2id(const char *name) * イベントキューのイベント処理 *------------------------------------------ */ -int npc_event_dequeue(struct map_session_data *sd) +int npc_event_dequeue(dumb_ptr<map_session_data> sd) { nullpo_ret(sd); @@ -144,7 +156,7 @@ int npc_event_dequeue(struct map_session_data *sd) return 0; } -int npc_delete(struct npc_data *nd) +int npc_delete(dumb_ptr<npc_data> nd) { nullpo_retr(1, nd); @@ -159,7 +171,7 @@ int npc_delete(struct npc_data *nd) int npc_timer_event(const char *eventname) // Added by RoVeRT { struct event_data *ev = ev_db.search(eventname); - struct npc_data *nd; + dumb_ptr<npc_data_script> nd; // int xs,ys; if ((ev == NULL || (nd = ev->nd) == NULL)) @@ -168,7 +180,7 @@ int npc_timer_event(const char *eventname) // Added by RoVeRT return 0; } - run_script(nd->u.scr.script, ev->pos, nd->bl_id, nd->bl_id); + run_script(nd->scr.script, ev->pos, nd->bl_id, nd->bl_id); return 0; } @@ -187,7 +199,7 @@ void npc_event_doall_sub(const std::string& key, struct event_data *ev, if ((p = strchr(p, ':')) && p && strcasecmp(name, p) == 0) { - run_script_l(ev->nd->u.scr.script, ev->pos, rid, ev->nd->bl_id, argc, + run_script_l(ev->nd->scr.script, ev->pos, rid, ev->nd->bl_id, argc, argv); (*c)++; } @@ -215,7 +227,7 @@ void npc_event_do_sub(const std::string& key, struct event_data *ev, if (p && strcasecmp(name, p) == 0) { - run_script_l(ev->nd->u.scr.script, ev->pos, rid, ev->nd->bl_id, argc, + run_script_l(ev->nd->scr.script, ev->pos, rid, ev->nd->bl_id, argc, argv); (*c)++; } @@ -291,55 +303,56 @@ int npc_event_do_oninit(void) static void npc_timerevent(TimerData *, tick_t tick, int id, interval_t data) { - struct npc_data *nd = (struct npc_data *) map_id2bl(id); + dumb_ptr<npc_data_script> nd = map_id2bl(id)->as_npc()->as_script(); struct npc_timerevent_list *te; assert (nd != NULL); - assert (nd->u.scr.nexttimer >= 0); + assert (nd->npc_subtype == NpcSubtype::SCRIPT); + assert (nd->scr.nexttimer >= 0); - nd->u.scr.timertick = tick; - te = nd->u.scr.timer_event + nd->u.scr.nexttimer; - // nd->u.scr.timerid = nullptr; + nd->scr.timertick = tick; + te = nd->scr.timer_event + nd->scr.nexttimer; + // nd->scr.timerid = nullptr; - interval_t t = nd->u.scr.timer += data; - nd->u.scr.nexttimer++; - if (nd->u.scr.timeramount > nd->u.scr.nexttimer) + interval_t t = nd->scr.timer += data; + nd->scr.nexttimer++; + if (nd->scr.timeramount > nd->scr.nexttimer) { - interval_t next = nd->u.scr.timer_event[nd->u.scr.nexttimer].timer - t; - nd->u.scr.timerid = Timer(tick + next, + interval_t next = nd->scr.timer_event[nd->scr.nexttimer].timer - t; + nd->scr.timerid = 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); + run_script(nd->scr.script, te->pos, 0, nd->bl_id); } /*========================================== * タイマーイベント開始 *------------------------------------------ */ -int npc_timerevent_start(struct npc_data *nd) +int npc_timerevent_start(dumb_ptr<npc_data_script> nd) { int j, n; nullpo_ret(nd); - n = nd->u.scr.timeramount; - if (nd->u.scr.nexttimer >= 0 || n == 0) + n = nd->scr.timeramount; + if (nd->scr.nexttimer >= 0 || n == 0) return 0; for (j = 0; j < n; j++) { - if (nd->u.scr.timer_event[j].timer > nd->u.scr.timer) + if (nd->scr.timer_event[j].timer > nd->scr.timer) break; } - nd->u.scr.nexttimer = j; - nd->u.scr.timertick = gettick(); + nd->scr.nexttimer = j; + nd->scr.timertick = gettick(); if (j >= n) return 0; - interval_t next = nd->u.scr.timer_event[j].timer - nd->u.scr.timer; - nd->u.scr.timerid = Timer(gettick() + next, + interval_t next = nd->scr.timer_event[j].timer - nd->scr.timer; + nd->scr.timerid = Timer(gettick() + next, std::bind(npc_timerevent, ph::_1, ph::_2, nd->bl_id, next)); return 0; @@ -349,15 +362,15 @@ int npc_timerevent_start(struct npc_data *nd) * タイマーイベント終了 *------------------------------------------ */ -int npc_timerevent_stop(struct npc_data *nd) +int npc_timerevent_stop(dumb_ptr<npc_data_script> nd) { nullpo_ret(nd); - if (nd->u.scr.nexttimer >= 0) + if (nd->scr.nexttimer >= 0) { - nd->u.scr.nexttimer = -1; - nd->u.scr.timer += gettick() - nd->u.scr.timertick; - nd->u.scr.timerid.cancel(); + nd->scr.nexttimer = -1; + nd->scr.timer += gettick() - nd->scr.timertick; + nd->scr.timerid.cancel(); } return 0; } @@ -366,14 +379,14 @@ int npc_timerevent_stop(struct npc_data *nd) * タイマー値の所得 *------------------------------------------ */ -interval_t npc_gettimerevent_tick(struct npc_data *nd) +interval_t npc_gettimerevent_tick(dumb_ptr<npc_data_script> nd) { nullpo_retr(interval_t::zero(), nd); - interval_t tick = nd->u.scr.timer; + interval_t tick = nd->scr.timer; - if (nd->u.scr.nexttimer >= 0) - tick += gettick() - nd->u.scr.timertick; + if (nd->scr.nexttimer >= 0) + tick += gettick() - nd->scr.timertick; return tick; } @@ -381,16 +394,16 @@ interval_t npc_gettimerevent_tick(struct npc_data *nd) * タイマー値の設定 *------------------------------------------ */ -int npc_settimerevent_tick(struct npc_data *nd, interval_t newtimer) +int npc_settimerevent_tick(dumb_ptr<npc_data_script> nd, interval_t newtimer) { int flag; nullpo_ret(nd); - flag = nd->u.scr.nexttimer; + flag = nd->scr.nexttimer; npc_timerevent_stop(nd); - nd->u.scr.timer = newtimer; + nd->scr.timer = newtimer; if (flag >= 0) npc_timerevent_start(nd); return 0; @@ -400,11 +413,11 @@ int npc_settimerevent_tick(struct npc_data *nd, interval_t newtimer) * イベント型のNPC処理 *------------------------------------------ */ -int npc_event(struct map_session_data *sd, const char *eventname, +int npc_event(dumb_ptr<map_session_data> sd, const char *eventname, int mob_kill) { struct event_data *ev = ev_db.search(eventname); - struct npc_data *nd; + dumb_ptr<npc_data_script> nd; int xs, ys; char mobevent[100]; @@ -439,8 +452,8 @@ int npc_event(struct map_session_data *sd, const char *eventname, } } - xs = nd->u.scr.xs; - ys = nd->u.scr.ys; + xs = nd->scr.xs; + ys = nd->scr.ys; if (xs >= 0 && ys >= 0) { if (nd->bl_m != sd->bl_m) @@ -483,7 +496,7 @@ int npc_event(struct map_session_data *sd, const char *eventname, sd->npc_id = nd->bl_id; sd->npc_pos = - run_script(nd->u.scr.script, ev->pos, sd->bl_id, nd->bl_id); + run_script(nd->scr.script, ev->pos, sd->bl_id, nd->bl_id); return 0; } @@ -499,11 +512,11 @@ void npc_command_sub(const std::string& key, struct event_data *ev, const char * sscanf(&p[11], "%s", temp); if (strcmp(command, temp) == 0) - run_script(ev->nd->u.scr.script, ev->pos, 0, ev->nd->bl_id); + run_script(ev->nd->scr.script, ev->pos, 0, ev->nd->bl_id); } } -int npc_command(struct map_session_data *, const char *npcname, const char *command) +int npc_command(dumb_ptr<map_session_data>, const char *npcname, const char *command) { for (auto& pair : ev_db) npc_command_sub(pair.first, &pair.second, npcname, command); @@ -515,7 +528,7 @@ int npc_command(struct map_session_data *, const char *npcname, const char *comm * 接触型のNPC処理 *------------------------------------------ */ -int npc_touch_areanpc(struct map_session_data *sd, int m, int x, int y) +int npc_touch_areanpc(dumb_ptr<map_session_data> sd, int m, int x, int y) { int i, f = 1; int xs, ys; @@ -536,13 +549,17 @@ int npc_touch_areanpc(struct map_session_data *sd, int m, int x, int y) switch (map[m].npc[i]->npc_subtype) { case NpcSubtype::WARP: - xs = map[m].npc[i]->u.warp.xs; - ys = map[m].npc[i]->u.warp.ys; + xs = map[m].npc[i]->as_warp()->warp.xs; + ys = map[m].npc[i]->as_warp()->warp.ys; break; case NpcSubtype::MESSAGE: + assert (0 && "I'm pretty sure these are never put on a map"); + xs = 0; + ys = 0; + break; case NpcSubtype::SCRIPT: - xs = map[m].npc[i]->u.scr.xs; - ys = map[m].npc[i]->u.scr.ys; + xs = map[m].npc[i]->as_script()->scr.xs; + ys = map[m].npc[i]->as_script()->scr.ys; break; default: continue; @@ -566,10 +583,12 @@ int npc_touch_areanpc(struct map_session_data *sd, int m, int x, int y) { case NpcSubtype::WARP: skill_stop_dancing(sd, 0); - pc_setpos(sd, map[m].npc[i]->u.warp.name, - map[m].npc[i]->u.warp.x, map[m].npc[i]->u.warp.y, BeingRemoveWhy::GONE); + pc_setpos(sd, map[m].npc[i]->as_warp()->warp.name, + map[m].npc[i]->as_warp()->warp.x, map[m].npc[i]->as_warp()->warp.y, BeingRemoveWhy::GONE); break; case NpcSubtype::MESSAGE: + assert (0 && "I'm pretty sure these NPCs are never put on a map."); + break; case NpcSubtype::SCRIPT: { char *name = (char *)malloc(50); @@ -592,19 +611,15 @@ int npc_touch_areanpc(struct map_session_data *sd, int m, int x, int y) *------------------------------------------ */ static -int npc_checknear(struct map_session_data *sd, int id) +int npc_checknear(dumb_ptr<map_session_data> sd, int id) { - struct npc_data *nd; + dumb_ptr<npc_data> nd; nullpo_ret(sd); - nd = (struct npc_data *) map_id2bl(id); - if (nd == NULL || nd->bl_type != BL::NPC) - { - if (battle_config.error_log) - PRINTF("no such npc : %d\n", id); - return 1; - } + nd = map_id_as_npc(id); + assert (nd != NULL); + assert (nd->bl_type == BL::NPC); if (nd->npc_class < 0) // イベント系は常にOK return 0; @@ -624,9 +639,9 @@ int npc_checknear(struct map_session_data *sd, int id) * クリック時のNPC処理 *------------------------------------------ */ -int npc_click(struct map_session_data *sd, int id) +int npc_click(dumb_ptr<map_session_data> sd, int id) { - struct npc_data *nd; + dumb_ptr<npc_data> nd; nullpo_retr(1, sd); @@ -642,7 +657,7 @@ int npc_click(struct map_session_data *sd, int id) return 1; } - nd = (struct npc_data *) map_id2bl(id); + nd = map_id_as_npc(id); if (nd->flag & 1) // 無効化されている return 1; @@ -655,12 +670,12 @@ int npc_click(struct map_session_data *sd, int id) npc_event_dequeue(sd); break; case NpcSubtype::SCRIPT: - sd->npc_pos = run_script(nd->u.scr.script, 0, sd->bl_id, id); + sd->npc_pos = run_script(nd->as_script()->scr.script, 0, sd->bl_id, id); break; case NpcSubtype::MESSAGE: - if (nd->u.message) + if (nd->as_message()->message) { - clif_scriptmes(sd, id, nd->u.message); + clif_scriptmes(sd, id, nd->as_message()->message); clif_scriptclose(sd, id); } break; @@ -673,20 +688,21 @@ int npc_click(struct map_session_data *sd, int id) * *------------------------------------------ */ -int npc_scriptcont(struct map_session_data *sd, int id) +int npc_scriptcont(dumb_ptr<map_session_data> sd, int id) { - struct npc_data *nd; + dumb_ptr<npc_data> nd; nullpo_retr(1, sd); if (id != sd->npc_id) return 1; - if (npc_checknear(sd, id)) { + if (npc_checknear(sd, id)) + { clif_scriptclose(sd, id); return 1; } - nd = (struct npc_data *) map_id2bl(id); + nd = map_id_as_npc(id); if (!nd /* NPC was disposed? */ || nd->npc_subtype == NpcSubtype::MESSAGE) { @@ -695,7 +711,7 @@ int npc_scriptcont(struct map_session_data *sd, int id) return 0; } - sd->npc_pos = run_script(nd->u.scr.script, sd->npc_pos, sd->bl_id, id); + sd->npc_pos = run_script(nd->as_script()->scr.script, sd->npc_pos, sd->bl_id, id); return 0; } @@ -704,16 +720,16 @@ int npc_scriptcont(struct map_session_data *sd, int id) * *------------------------------------------ */ -int npc_buysellsel(struct map_session_data *sd, int id, int type) +int npc_buysellsel(dumb_ptr<map_session_data> sd, int id, int type) { - struct npc_data *nd; + dumb_ptr<npc_data> nd; nullpo_retr(1, sd); if (npc_checknear(sd, id)) return 1; - nd = (struct npc_data *) map_id2bl(id); + nd = map_id_as_npc(id); if (nd->npc_subtype != NpcSubtype::SHOP) { if (battle_config.error_log) @@ -727,7 +743,7 @@ int npc_buysellsel(struct map_session_data *sd, int id, int type) sd->npc_shopid = id; if (type == 0) { - clif_buylist(sd, nd); + clif_buylist(sd, nd->as_shop()); } else { @@ -741,10 +757,10 @@ int npc_buysellsel(struct map_session_data *sd, int id, int type) *------------------------------------------ */ // TODO enumify return type -int npc_buylist(struct map_session_data *sd, int n, +int npc_buylist(dumb_ptr<map_session_data> sd, int n, const uint16_t *item_list) { - struct npc_data *nd; + dumb_ptr<npc_data> nd; double z; int i, j, w, itemamount = 0, new_stacks = 0; @@ -754,21 +770,21 @@ int npc_buylist(struct map_session_data *sd, int n, if (npc_checknear(sd, sd->npc_shopid)) return 3; - nd = (struct npc_data *) map_id2bl(sd->npc_shopid); + nd = map_id_as_npc(sd->npc_shopid); if (nd->npc_subtype != NpcSubtype::SHOP) return 3; for (i = 0, w = 0, z = 0; i < n; i++) { - for (j = 0; nd->u.shop_item[j].nameid; j++) + for (j = 0; j < nd->as_shop()->shop_items.size(); j++) { - if (nd->u.shop_item[j].nameid == item_list[i * 2 + 1]) + if (nd->as_shop()->shop_items[j].nameid == item_list[i * 2 + 1]) break; } - if (nd->u.shop_item[j].nameid == 0) + if (j == nd->as_shop()->shop_items.size()) return 3; - z += (double) nd->u.shop_item[j].value * item_list[i * 2]; + z += (double) nd->as_shop()->shop_items[j].value * item_list[i * 2]; itemamount += item_list[i * 2]; switch (pc_checkadditem(sd, item_list[i * 2 + 1], item_list[i * 2])) @@ -836,7 +852,7 @@ int npc_buylist(struct map_session_data *sd, int n, * *------------------------------------------ */ -int npc_selllist(struct map_session_data *sd, int n, +int npc_selllist(dumb_ptr<map_session_data> sd, int n, const uint16_t *item_list) { double z; @@ -961,7 +977,7 @@ int npc_parse_warp(const char *w1, const char *, const char *w3, const char *w4) int x, y, xs, ys, to_x, to_y, m; int i, j; char mapname[24], to_mapname[24]; - struct npc_data *nd; + dumb_ptr<npc_data_warp> nd; // 引数の個数チェック if (sscanf(w1, "%[^,],%d,%d", mapname, &x, &y) != 3 || @@ -974,7 +990,7 @@ int npc_parse_warp(const char *w1, const char *, const char *w3, const char *w4) m = map_mapname2mapid(mapname); - nd = (struct npc_data *) calloc(1, sizeof(struct npc_data)); + nd.new_(); nd->bl_id = npc_get_new_npc_id(); nd->n = map_addnpc(m, nd); @@ -987,7 +1003,6 @@ int npc_parse_warp(const char *w1, const char *, const char *w3, const char *w4) memcpy(nd->name, w3, 24); memcpy(nd->exname, w3, 24); - nd->chat_id = 0; if (!battle_config.warp_point_debug) nd->npc_class = WARP_CLASS; else @@ -997,13 +1012,13 @@ int npc_parse_warp(const char *w1, const char *, const char *w3, const char *w4) nd->opt1 = Opt1::ZERO; nd->opt2 = Opt2::ZERO; nd->opt3 = Opt3::ZERO; - memcpy(nd->u.warp.name, to_mapname, 16); + memcpy(nd->warp.name, to_mapname, 16); xs += 2; ys += 2; - nd->u.warp.x = to_x; - nd->u.warp.y = to_y; - nd->u.warp.xs = xs; - nd->u.warp.ys = ys; + nd->warp.x = to_x; + nd->warp.y = to_y; + nd->warp.xs = xs; + nd->warp.ys = ys; for (i = 0; i < ys; i++) { @@ -1042,9 +1057,8 @@ int npc_parse_shop(char *w1, char *, char *w3, char *w4) int x, y; DIR dir; int m; - int max = 100, pos = 0; char mapname[24]; - struct npc_data *nd; + dumb_ptr<npc_data_shop> nd; // 引数の個数チェック int dir_; // TODO use SSCANF or extract @@ -1058,12 +1072,10 @@ int npc_parse_shop(char *w1, char *, char *w3, char *w4) dir = static_cast<DIR>(dir_); m = map_mapname2mapid(mapname); - nd = (struct npc_data *) calloc(1, sizeof(struct npc_data) + - sizeof(nd->u.shop_item[0]) * (max + - 1)); + nd.new_(); p = strchr(w4, ','); - while (p && pos < max) + while (p) { int nameid, value; char name[24]; @@ -1085,7 +1097,8 @@ int npc_parse_shop(char *w1, char *, char *w3, char *w4) if (nameid > 0) { - nd->u.shop_item[pos].nameid = nameid; + npc_item_list sh_it; + sh_it.nameid = nameid; if (value < 0) { if (id == NULL) @@ -1093,17 +1106,16 @@ int npc_parse_shop(char *w1, char *, char *w3, char *w4) value = id->value_buy * abs(value); } - nd->u.shop_item[pos].value = value; - pos++; + sh_it.value = value; + nd->shop_items.push_back(sh_it); } p = strchr(p, ','); } - if (pos == 0) + if (nd->shop_items.empty()) { - free(nd); + nd.delete_(); return 1; } - nd->u.shop_item[pos++].nameid = 0; nd->bl_prev = nd->bl_next = NULL; nd->bl_m = m; @@ -1115,15 +1127,11 @@ int npc_parse_shop(char *w1, char *, char *w3, char *w4) memcpy(nd->name, w3, 24); nd->npc_class = atoi(w4); nd->speed = std::chrono::milliseconds(200); - nd->chat_id = 0; nd->option = Option::ZERO; nd->opt1 = Opt1::ZERO; nd->opt2 = Opt2::ZERO; nd->opt3 = Opt3::ZERO; - nd = (struct npc_data *) - realloc(nd, sizeof(struct npc_data) + sizeof(nd->u.shop_item[0]) * pos); - //PRINTF("shop npc %s %d read done\n",mapname,nd->bl_id); npc_shop++; nd->bl_type = BL::NPC; @@ -1141,15 +1149,15 @@ int npc_parse_shop(char *w1, char *, char *w3, char *w4) *------------------------------------------ */ static -void npc_convertlabel_db(const std::string& lname, int pos, struct npc_data *nd) +void npc_convertlabel_db(const std::string& lname, int pos, dumb_ptr<npc_data_script> nd) { struct npc_label_list *lst; int num; nullpo_retv(nd); - lst = nd->u.scr.label_list; - num = nd->u.scr.label_list_num; + lst = nd->scr.label_list; + num = nd->scr.label_list_num; if (!lst) { lst = (struct npc_label_list *) @@ -1162,8 +1170,8 @@ void npc_convertlabel_db(const std::string& lname, int pos, struct npc_data *nd) strzcpy(lst[num].name, lname.c_str(), sizeof(lst[num].name)); lst[num].pos = pos; - nd->u.scr.label_list = lst; - nd->u.scr.label_list_num = num + 1; + nd->scr.label_list = lst; + nd->scr.label_list_num = num + 1; } /*========================================== @@ -1183,7 +1191,7 @@ int npc_parse_script(char *w1, char *w2, char *w3, char *w4, int srcsize = 65536; int startline = 0; char line[1024]; - struct npc_data *nd; + dumb_ptr<npc_data_script> nd; int evflag = 0; char *p; struct npc_label_list *label_dup = NULL; @@ -1261,33 +1269,15 @@ int npc_parse_script(char *w1, char *w2, char *w3, char *w4, } else { - // duplicateする - - char srcname[128]; - struct npc_data *nd2; - if (sscanf(w2, "duplicate (%[^)])", srcname) != 1) - { - PRINTF("bad duplicate name! : %s", w2); - return 0; - } - if ((nd2 = npc_name2id(srcname)) == NULL) - { - PRINTF("bad duplicate name! (not exist) : %s\n", srcname); - return 0; - } - script = nd2->u.scr.script; - label_dup = nd2->u.scr.label_list; - label_dupnum = nd2->u.scr.label_list_num; - src_id = nd2->bl_id; - + PRINTF("duplicate() is no longer supported!\n"); + return 0; } // end of スクリプト解析 - nd = (struct npc_data *) calloc(1, sizeof(struct npc_data)); + nd.new_(); if (m == -1) { // スクリプトコピー用のダミーNPC - } else if (sscanf(w4, "%d,%d,%d", &npc_class, &xs, &ys) == 3) { @@ -1318,14 +1308,14 @@ int npc_parse_script(char *w1, char *w2, char *w3, char *w4, } } - nd->u.scr.xs = xs; - nd->u.scr.ys = ys; + nd->scr.xs = xs; + nd->scr.ys = ys; } else { // クリック型NPC npc_class = atoi(w4); - nd->u.scr.xs = 0; - nd->u.scr.ys = 0; + nd->scr.xs = 0; + nd->scr.ys = 0; } if (npc_class < 0 && m >= 0) @@ -1359,9 +1349,8 @@ int npc_parse_script(char *w1, char *w2, char *w3, char *w4, nd->flag = 0; nd->npc_class = npc_class; nd->speed = std::chrono::milliseconds(200); - nd->u.scr.script = script; - nd->u.scr.src_id = src_id; - nd->chat_id = 0; + nd->scr.script = script; + nd->scr.src_id = src_id; nd->option = Option::ZERO; nd->opt1 = Opt1::ZERO; nd->opt2 = Opt2::ZERO; @@ -1406,19 +1395,19 @@ int npc_parse_script(char *w1, char *w2, char *w3, char *w4, { // duplicate -// nd->u.scr.label_list=malloc(sizeof(struct npc_label_list)*label_dupnum); -// memcpy(nd->u.scr.label_list,label_dup,sizeof(struct npc_label_list)*label_dupnum); +// nd->scr.label_list=malloc(sizeof(struct npc_label_list)*label_dupnum); +// memcpy(nd->scr.label_list,label_dup,sizeof(struct npc_label_list)*label_dupnum); - nd->u.scr.label_list = label_dup; // ラベルデータ共有 - nd->u.scr.label_list_num = label_dupnum; + nd->scr.label_list = label_dup; // ラベルデータ共有 + nd->scr.label_list_num = label_dupnum; } //----------------------------------------- // イベント用ラベルデータのエクスポート - for (int i = 0; i < nd->u.scr.label_list_num; i++) + for (int i = 0; i < nd->scr.label_list_num; i++) { - char *lname = nd->u.scr.label_list[i].name; - int pos = nd->u.scr.label_list[i].pos; + char *lname = nd->scr.label_list[i].name; + int pos = nd->scr.label_list[i].pos; if ((lname[0] == 'O' || lname[0] == 'o') && (lname[1] == 'N' || lname[1] == 'n')) @@ -1438,17 +1427,17 @@ int npc_parse_script(char *w1, char *w2, char *w3, char *w4, //----------------------------------------- // ラベルデータからタイマーイベント取り込み - for (int i = 0; i < nd->u.scr.label_list_num; i++) + for (int i = 0; i < nd->scr.label_list_num; i++) { int t_ = 0, n = 0; - char *lname = nd->u.scr.label_list[i].name; - int pos = nd->u.scr.label_list[i].pos; + char *lname = nd->scr.label_list[i].name; + int pos = nd->scr.label_list[i].pos; 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; + struct npc_timerevent_list *te = nd->scr.timer_event; + int j, k = nd->scr.timeramount; if (te == NULL) te = (struct npc_timerevent_list *) calloc(1, sizeof(struct @@ -1469,12 +1458,12 @@ int npc_parse_script(char *w1, char *w2, char *w3, char *w4, } te[j].timer = t; te[j].pos = pos; - nd->u.scr.timer_event = te; - nd->u.scr.timeramount = k + 1; + nd->scr.timer_event = te; + nd->scr.timeramount = k + 1; } } - nd->u.scr.nexttimer = -1; - // nd->u.scr.timerid = nullptr; + nd->scr.nexttimer = -1; + // nd->scr.timerid = nullptr; return 0; } @@ -1558,7 +1547,7 @@ int npc_parse_mob(const char *w1, const char *, const char *w3, const char *w4) int i; char mapname[24]; char eventname[24] = ""; - struct mob_data *md; + dumb_ptr<mob_data> md; xs = ys = 0; int delay1_ = 0, delay2_ = 0; @@ -1583,7 +1572,7 @@ int npc_parse_mob(const char *w1, const char *, const char *w3, const char *w4) for (i = 0; i < num; i++) { - md = (struct mob_data *) calloc(1, sizeof(struct mob_data)); + md.new_(); md->bl_prev = NULL; md->bl_next = NULL; @@ -1767,11 +1756,11 @@ int npc_parse_mapflag(char *w1, char *, char *w3, char *w4) return 0; } -struct npc_data *npc_spawn_text(int m, int x, int y, +dumb_ptr<npc_data> npc_spawn_text(int m, int x, int y, int npc_class, const char *name, const char *message) { - struct npc_data *retval = - (struct npc_data *) calloc(1, sizeof(struct npc_data)); + dumb_ptr<npc_data_message> retval; + retval.new_(); retval->bl_id = npc_get_new_npc_id(); retval->bl_x = x; retval->bl_y = y; @@ -1783,7 +1772,7 @@ struct npc_data *npc_spawn_text(int m, int x, int y, strncpy(retval->exname, name, 23); retval->name[15] = 0; retval->exname[15] = 0; - retval->u.message = message ? strdup(message) : NULL; + retval->message = message ? strdup(message) : NULL; retval->npc_class = npc_class; retval->speed = std::chrono::milliseconds(200); @@ -1798,49 +1787,50 @@ struct npc_data *npc_spawn_text(int m, int x, int y, } static -void npc_free_internal(struct npc_data *nd) +void npc_free_internal(dumb_ptr<npc_data> nd_) { - struct chat_data *cd; - - if (nd->chat_id && (cd = (struct chat_data *) map_id2bl(nd->chat_id))) + if (nd_->npc_subtype == NpcSubtype::SCRIPT) { - free(cd); - cd = NULL; - } - if (nd->npc_subtype == NpcSubtype::SCRIPT) - { - if (nd->u.scr.timer_event) - free(nd->u.scr.timer_event); - if (nd->u.scr.src_id == 0) + dumb_ptr<npc_data_script> nd = nd_->as_script(); + if (nd->scr.timer_event) + free(nd->scr.timer_event); + if (nd->scr.src_id == 0) { - if (nd->u.scr.script) + if (nd->scr.script) { - free(const_cast<ScriptCode *>(nd->u.scr.script)); - nd->u.scr.script = NULL; + free(const_cast<ScriptCode *>(nd->scr.script)); + nd->scr.script = NULL; } - if (nd->u.scr.label_list) + if (nd->scr.label_list) { - free(nd->u.scr.label_list); - nd->u.scr.label_list = NULL; + free(nd->scr.label_list); + nd->scr.label_list = NULL; } } } - else if (nd->npc_subtype == NpcSubtype::MESSAGE && nd->u.message) + else if (nd_->npc_subtype == NpcSubtype::MESSAGE) { - free(nd->u.message); + dumb_ptr<npc_data_message> nd = nd_->as_message(); + free(nd->message); } - free(nd); + nd_.delete_(); } static -void npc_propagate_update(struct npc_data *nd) +void npc_propagate_update(dumb_ptr<npc_data> nd) { + int xs = 0, ys = 0; + if (dumb_ptr<npc_data_script> nd_ = nd->is_script()) + { + xs = nd_->scr.xs; + ys = nd_->scr.ys; + } map_foreachinarea(std::bind(npc_enable_sub, ph::_1, nd), - nd->bl_m, nd->bl_x - nd->u.scr.xs, nd->bl_y - nd->u.scr.ys, - nd->bl_x + nd->u.scr.xs, nd->bl_y + nd->u.scr.ys, BL::PC); + nd->bl_m, nd->bl_x - xs, nd->bl_y - ys, + nd->bl_x + xs, nd->bl_y + ys, BL::PC); } -void npc_free(struct npc_data *nd) +void npc_free(dumb_ptr<npc_data> nd) { clif_clearchar(nd, BeingRemoveWhy::GONE); npc_propagate_update(nd); diff --git a/src/map/npc.hpp b/src/map/npc.hpp index bedca83..5760ca1 100644 --- a/src/map/npc.hpp +++ b/src/map/npc.hpp @@ -6,26 +6,28 @@ #include "../common/timer.t.hpp" +#include "map.hpp" + constexpr int START_NPC_NUM = 110000000; constexpr int WARP_CLASS = 45; constexpr int WARP_DEBUG_CLASS = 722; constexpr int INVISIBLE_CLASS = 32767; -int npc_event_dequeue(struct map_session_data *sd); -int npc_event(struct map_session_data *sd, const char *npcname, int); +int npc_event_dequeue(dumb_ptr<map_session_data> sd); +int npc_event(dumb_ptr<map_session_data> sd, const char *npcname, int); int npc_timer_event(const char *eventname); // Added by RoVeRT -int npc_command(struct map_session_data *sd, const char *npcname, const char *command); -int npc_touch_areanpc(struct map_session_data *, int, int, int); -int npc_click(struct map_session_data *, int); -int npc_scriptcont(struct map_session_data *, int); -int npc_buysellsel(struct map_session_data *, int, int); -int npc_buylist(struct map_session_data *, int, const uint16_t *); -int npc_selllist(struct map_session_data *, int, const uint16_t *); +int npc_command(dumb_ptr<map_session_data> sd, const char *npcname, const char *command); +int npc_touch_areanpc(dumb_ptr<map_session_data>, int, int, int); +int npc_click(dumb_ptr<map_session_data>, int); +int npc_scriptcont(dumb_ptr<map_session_data>, int); +int npc_buysellsel(dumb_ptr<map_session_data>, int, int); +int npc_buylist(dumb_ptr<map_session_data>, int, const uint16_t *); +int npc_selllist(dumb_ptr<map_session_data>, int, const uint16_t *); int npc_parse_warp(const char *w1, const char *w2, const char *w3, const char *w4); int npc_enable(const char *name, bool flag); -struct npc_data *npc_name2id(const char *name); +dumb_ptr<npc_data> npc_name2id(const char *name); int npc_get_new_npc_id(void); @@ -34,12 +36,12 @@ int npc_get_new_npc_id(void); * * \param message The message to speak. If message is NULL, the NPC will not do anything at all. */ -struct npc_data *npc_spawn_text(int m, int x, int y, int class_, const char *name, const char *message); // message is strdup'd within +dumb_ptr<npc_data> npc_spawn_text(int m, int x, int y, int class_, const char *name, const char *message); // message is strdup'd within /** * Uninstalls and frees an NPC */ -void npc_free(struct npc_data *npc); +void npc_free(dumb_ptr<npc_data> npc); void npc_addsrcfile(const char *); void npc_delsrcfile(const char *); @@ -62,10 +64,10 @@ int npc_event_do(const char *name) return npc_event_do_l(name, 0, 0, NULL); } -int npc_timerevent_start(struct npc_data *nd); -int npc_timerevent_stop(struct npc_data *nd); -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); +int npc_timerevent_start(dumb_ptr<npc_data_script> nd); +int npc_timerevent_stop(dumb_ptr<npc_data_script> nd); +interval_t npc_gettimerevent_tick(dumb_ptr<npc_data_script> nd); +int npc_settimerevent_tick(dumb_ptr<npc_data_script> nd, interval_t newtimer); +int npc_delete(dumb_ptr<npc_data> nd); #endif // NPC_HPP diff --git a/src/map/party.cpp b/src/map/party.cpp index c1488c0..1f2c78a 100644 --- a/src/map/party.cpp +++ b/src/map/party.cpp @@ -24,7 +24,7 @@ static Map<int, struct party> party_db; static -int party_check_conflict(struct map_session_data *sd); +int party_check_conflict(dumb_ptr<map_session_data> sd); static void party_send_xyhp_timer(TimerData *tid, tick_t tick); @@ -60,7 +60,7 @@ struct party *party_searchname(const char *str) } /* Process a party creation request. */ -int party_create(struct map_session_data *sd, const char *name) +int party_create(dumb_ptr<map_session_data> sd, const char *name) { char pname[24]; nullpo_ret(sd); @@ -85,7 +85,7 @@ int party_create(struct map_session_data *sd, const char *name) /* Relay the result of a party creation request. */ int party_created(int account_id, int fail, int party_id, const char *name) { - struct map_session_data *sd; + dumb_ptr<map_session_data> sd; sd = map_id2sd(account_id); nullpo_ret(sd); @@ -202,17 +202,17 @@ int party_recv_info(const struct party *sp) for (i = 0; i < MAX_PARTY; i++) { // sdの設定 - struct map_session_data *sd = map_id2sd(p->member[i].account_id); + dumb_ptr<map_session_data> sd = map_id2sd(p->member[i].account_id); p->member[i].sd = (sd != NULL - && sd->status.party_id == p->party_id) ? sd : NULL; + && sd->status.party_id == p->party_id) ? sd.operator->() : NULL; } clif_party_info(p, -1); for (i = 0; i < MAX_PARTY; i++) { // 設定情報の送信 -// struct map_session_data *sd = map_id2sd(p->member[i].account_id); - struct map_session_data *sd = p->member[i].sd; +// dumb_ptr<map_session_data> sd = map_id2sd(p->member[i].account_id); + dumb_ptr<map_session_data> sd = dumb_ptr<map_session_data>(p->member[i].sd); if (sd != NULL && sd->party_sended == 0) { clif_party_option(p, sd, 0x100); @@ -224,9 +224,9 @@ int party_recv_info(const struct party *sp) } /* Process party invitation from sd to account_id. */ -int party_invite(struct map_session_data *sd, int account_id) +int party_invite(dumb_ptr<map_session_data> sd, int account_id) { - struct map_session_data *tsd = map_id2sd(account_id); + dumb_ptr<map_session_data> tsd = map_id2sd(account_id); struct party *p = party_search(sd->status.party_id); int i; int full = 1; /* Indicates whether or not there's room for one more. */ @@ -288,7 +288,7 @@ int party_invite(struct map_session_data *sd, int account_id) } /* Process response to party invitation. */ -int party_reply_invite(struct map_session_data *sd, int account_id, int flag) +int party_reply_invite(dumb_ptr<map_session_data> sd, int account_id, int flag) { nullpo_ret(sd); @@ -310,7 +310,7 @@ int party_reply_invite(struct map_session_data *sd, int account_id, int flag) else { /* This is the player who sent the invitation. */ - struct map_session_data *tsd = NULL; + dumb_ptr<map_session_data> tsd = NULL; sd->party_invite = 0; sd->party_invite_account = 0; @@ -324,7 +324,7 @@ int party_reply_invite(struct map_session_data *sd, int account_id, int flag) // パーティが追加された int party_member_added(int party_id, int account_id, int flag) { - struct map_session_data *sd = map_id2sd(account_id), *sd2; + dumb_ptr<map_session_data> sd = map_id2sd(account_id), sd2; struct party *p = party_search(party_id); if (sd == NULL) @@ -372,7 +372,7 @@ int party_member_added(int party_id, int account_id, int flag) } // パーティ除名要求 -int party_removemember(struct map_session_data *sd, int account_id, const char *) +int party_removemember(dumb_ptr<map_session_data> sd, int account_id, const char *) { struct party *p; int i; @@ -401,7 +401,7 @@ int party_removemember(struct map_session_data *sd, int account_id, const char * } // パーティ脱退要求 -int party_leave(struct map_session_data *sd) +int party_leave(dumb_ptr<map_session_data> sd) { struct party *p; int i; @@ -425,7 +425,7 @@ int party_leave(struct map_session_data *sd) // パーティメンバが脱退した int party_member_leaved(int party_id, int account_id, const char *name) { - struct map_session_data *sd = map_id2sd(account_id); + dumb_ptr<map_session_data> sd = map_id2sd(account_id); struct party *p = party_search(party_id); if (p != NULL) { @@ -458,7 +458,7 @@ int party_broken(int party_id) { if (p->member[i].sd != NULL) { - clif_party_leaved(p, p->member[i].sd, + clif_party_leaved(p, dumb_ptr<map_session_data>(p->member[i].sd), p->member[i].account_id, p->member[i].name, 0x10); p->member[i].sd->status.party_id = 0; @@ -470,7 +470,7 @@ int party_broken(int party_id) } // パーティの設定変更要求 -int party_changeoption(struct map_session_data *sd, int exp, int item) +int party_changeoption(dumb_ptr<map_session_data> sd, int exp, int item) { struct party *p; @@ -489,7 +489,7 @@ int party_optionchanged(int party_id, int account_id, int exp, int item, int flag) { struct party *p; - struct map_session_data *sd = map_id2sd(account_id); + dumb_ptr<map_session_data> sd = map_id2sd(account_id); if ((p = party_search(party_id)) == NULL) return 0; @@ -535,9 +535,9 @@ int party_recv_movemap(int party_id, int account_id, const char *mapname, int on for (i = 0; i < MAX_PARTY; i++) { // sd再設定 - struct map_session_data *sd = map_id2sd(p->member[i].account_id); + dumb_ptr<map_session_data> sd = map_id2sd(p->member[i].account_id); p->member[i].sd = (sd != NULL - && sd->status.party_id == p->party_id) ? sd : NULL; + && sd->status.party_id == p->party_id) ? sd.operator->() : NULL; } party_send_xy_clear(p); // 座標再通知要請 @@ -547,7 +547,7 @@ int party_recv_movemap(int party_id, int account_id, const char *mapname, int on } // パーティメンバの移動 -int party_send_movemap(struct map_session_data *sd) +int party_send_movemap(dumb_ptr<map_session_data> sd) { struct party *p; @@ -579,7 +579,7 @@ int party_send_movemap(struct map_session_data *sd) } // パーティメンバのログアウト -int party_send_logout(struct map_session_data *sd) +int party_send_logout(dumb_ptr<map_session_data> sd) { struct party *p; @@ -593,7 +593,7 @@ int party_send_logout(struct map_session_data *sd) { int i; for (i = 0; i < MAX_PARTY; i++) - if (p->member[i].sd == sd) + if (dumb_ptr<map_session_data>(p->member[i].sd) == sd) p->member[i].sd = NULL; } @@ -601,7 +601,7 @@ int party_send_logout(struct map_session_data *sd) } // パーティメッセージ送信 -int party_send_message(struct map_session_data *sd, const char *mes, int len) +int party_send_message(dumb_ptr<map_session_data> sd, const char *mes, int len) { if (sd->status.party_id == 0) return 0; @@ -621,7 +621,7 @@ int party_recv_message(int party_id, int account_id, const char *mes, int len) } // パーティ競合確認 -int party_check_conflict(struct map_session_data *sd) +int party_check_conflict(dumb_ptr<map_session_data> sd) { nullpo_ret(sd); @@ -640,8 +640,8 @@ void party_send_xyhp_timer_sub(struct party *p) for (i = 0; i < MAX_PARTY; i++) { - struct map_session_data *sd; - if ((sd = p->member[i].sd) != NULL) + dumb_ptr<map_session_data> sd = dumb_ptr<map_session_data>(p->member[i].sd); + if (sd != NULL) { // 座標通知 if (sd->party_x != sd->bl_x || sd->party_y != sd->bl_y) @@ -677,8 +677,8 @@ int party_send_xy_clear(struct party *p) for (i = 0; i < MAX_PARTY; i++) { - struct map_session_data *sd; - if ((sd = p->member[i].sd) != NULL) + dumb_ptr<map_session_data> sd = dumb_ptr<map_session_data>(p->member[i].sd); + if (sd != NULL) { sd->party_x = -1; sd->party_y = -1; @@ -689,12 +689,12 @@ int party_send_xy_clear(struct party *p) } // HP通知の必要性検査用(map_foreachinmoveareaから呼ばれる) -void party_send_hp_check(struct block_list *bl, int party_id, int *flag) +void party_send_hp_check(dumb_ptr<block_list> bl, int party_id, int *flag) { - struct map_session_data *sd; + dumb_ptr<map_session_data> sd; nullpo_retv(bl); - sd = (struct map_session_data *) bl; + sd = bl->as_player(); if (sd->status.party_id == party_id) { @@ -706,33 +706,39 @@ void party_send_hp_check(struct block_list *bl, int party_id, int *flag) // 経験値公平分配 int party_exp_share(struct party *p, int mapid, int base_exp, int job_exp) { - struct map_session_data *sd; + dumb_ptr<map_session_data> sd; int i, c; nullpo_ret(p); for (i = c = 0; i < MAX_PARTY; i++) - if ((sd = p->member[i].sd) != NULL && sd->bl_m == mapid) + { + sd = dumb_ptr<map_session_data>(p->member[i].sd); + if (sd != NULL && sd->bl_m == mapid) c++; + } if (c == 0) return 0; for (i = 0; i < MAX_PARTY; i++) - if ((sd = p->member[i].sd) != NULL && sd->bl_m == mapid) + { + sd = dumb_ptr<map_session_data>(p->member[i].sd); + if (sd != NULL && sd->bl_m == mapid) pc_gainexp_reason(sd, base_exp / c + 1, job_exp / c + 1, PC_GAINEXP_REASON::SHARING); + } return 0; } // 同じマップのパーティメンバー全体に処理をかける // type==0 同じマップ // !=0 画面内 -void party_foreachsamemap(std::function<void(struct block_list *)> func, - struct map_session_data *sd, int type) +void party_foreachsamemap(std::function<void(dumb_ptr<block_list>)> func, + dumb_ptr<map_session_data> sd, int type) { struct party *p; int i; int x0, y0, x1, y1; - struct block_list *list[MAX_PARTY]; + dumb_ptr<map_session_data> list[MAX_PARTY]; int blockcount = 0; nullpo_retv(sd); @@ -756,7 +762,7 @@ void party_foreachsamemap(std::function<void(struct block_list *)> func, (m->sd->bl_x < x0 || m->sd->bl_y < y0 || m->sd->bl_x > x1 || m->sd->bl_y > y1)) continue; - list[blockcount++] = m->sd; + list[blockcount++] = dumb_ptr<map_session_data>(m->sd); } } diff --git a/src/map/party.hpp b/src/map/party.hpp index 77e3aaf..e2cabb3 100644 --- a/src/map/party.hpp +++ b/src/map/party.hpp @@ -3,6 +3,8 @@ #include <functional> +#include "map.hpp" + struct party; struct map_session_data; struct block_list; @@ -11,16 +13,16 @@ void do_init_party(void); struct party *party_search(int party_id); struct party *party_searchname(const char *str); -int party_create(struct map_session_data *sd, const char *name); +int party_create(dumb_ptr<map_session_data> sd, const char *name); int party_created(int account_id, int fail, int party_id, const char *name); int party_request_info(int party_id); -int party_invite(struct map_session_data *sd, int account_id); +int party_invite(dumb_ptr<map_session_data> sd, int account_id); int party_member_added(int party_id, int account_id, int flag); -int party_leave(struct map_session_data *sd); -int party_removemember(struct map_session_data *sd, int account_id, +int party_leave(dumb_ptr<map_session_data> sd); +int party_removemember(dumb_ptr<map_session_data> sd, int account_id, const char *name); int party_member_leaved(int party_id, int account_id, const char *name); -int party_reply_invite(struct map_session_data *sd, int account_id, +int party_reply_invite(dumb_ptr<map_session_data> sd, int account_id, int flag); int party_recv_noinfo(int party_id); int party_recv_info(const struct party *sp); @@ -29,20 +31,20 @@ int party_recv_movemap(int party_id, int account_id, const char *map, int party_broken(int party_id); int party_optionchanged(int party_id, int account_id, int exp, int item, int flag); -int party_changeoption(struct map_session_data *sd, int exp, int item); +int party_changeoption(dumb_ptr<map_session_data> sd, int exp, int item); -int party_send_movemap(struct map_session_data *sd); -int party_send_logout(struct map_session_data *sd); +int party_send_movemap(dumb_ptr<map_session_data> sd); +int party_send_logout(dumb_ptr<map_session_data> sd); -int party_send_message(struct map_session_data *sd, const char *mes, int len); +int party_send_message(dumb_ptr<map_session_data> sd, const char *mes, int len); int party_recv_message(int party_id, int account_id, const char *mes, int len); int party_send_xy_clear(struct party *p); -void party_send_hp_check(struct block_list *bl, int party_id, int *flag); +void party_send_hp_check(dumb_ptr<block_list> bl, int party_id, int *flag); int party_exp_share(struct party *p, int map, int base_exp, int job_exp); -void party_foreachsamemap(std::function<void(struct block_list *)> func, - struct map_session_data *sd, int type); +void party_foreachsamemap(std::function<void(dumb_ptr<block_list>)> func, + dumb_ptr<map_session_data> sd, int type); #endif // PARTY_HPP diff --git a/src/map/pc.cpp b/src/map/pc.cpp index 59dbfad..23e7f81 100644 --- a/src/map/pc.cpp +++ b/src/map/pc.cpp @@ -221,20 +221,20 @@ static int GM_num = 0; static -int pc_checkoverhp(struct map_session_data *sd); +int pc_checkoverhp(dumb_ptr<map_session_data> sd); static -int pc_checkoversp(struct map_session_data *sd); +int pc_checkoversp(dumb_ptr<map_session_data> sd); static -int pc_nextbaseafter(struct map_session_data *sd); +int pc_nextbaseafter(dumb_ptr<map_session_data> sd); static -int pc_nextjobafter(struct map_session_data *sd); +int pc_nextjobafter(dumb_ptr<map_session_data> sd); static -void pc_setdead(struct map_session_data *sd) +void pc_setdead(dumb_ptr<map_session_data> sd) { sd->state.dead_sit = 1; } -int pc_isGM(struct map_session_data *sd) +int pc_isGM(dumb_ptr<map_session_data> sd) { int i; @@ -247,8 +247,8 @@ int pc_isGM(struct map_session_data *sd) } -int pc_iskiller(struct map_session_data *src, - struct map_session_data *target) +int pc_iskiller(dumb_ptr<map_session_data> src, + dumb_ptr<map_session_data> target) { nullpo_ret(src); @@ -297,13 +297,13 @@ int distance(int x0, int y0, int x1, int y1) static void pc_invincible_timer(TimerData *, tick_t, int id) { - struct map_session_data *sd = map_id2sd(id); + dumb_ptr<map_session_data> sd = map_id2sd(id); assert (sd != NULL); assert (sd->bl_type == BL::PC); } -int pc_setinvincibletimer(struct map_session_data *sd, interval_t val) +int pc_setinvincibletimer(dumb_ptr<map_session_data> sd, interval_t val) { nullpo_ret(sd); @@ -313,7 +313,7 @@ int pc_setinvincibletimer(struct map_session_data *sd, interval_t val) return 0; } -int pc_delinvincibletimer(struct map_session_data *sd) +int pc_delinvincibletimer(dumb_ptr<map_session_data> sd) { nullpo_ret(sd); @@ -321,7 +321,7 @@ int pc_delinvincibletimer(struct map_session_data *sd) return 0; } -int pc_setrestartvalue(struct map_session_data *sd, int type) +int pc_setrestartvalue(dumb_ptr<map_session_data> sd, int type) { nullpo_ret(sd); @@ -362,8 +362,8 @@ int pc_setrestartvalue(struct map_session_data *sd, int type) *------------------------------------------ */ static -void pc_counttargeted_sub(struct block_list *bl, - int id, int *c, struct block_list *src, ATK target_lv) +void pc_counttargeted_sub(dumb_ptr<block_list> bl, + int id, int *c, dumb_ptr<block_list> src, ATK target_lv) { nullpo_retv(bl); @@ -371,14 +371,14 @@ void pc_counttargeted_sub(struct block_list *bl, return; if (bl->bl_type == BL::PC) { - struct map_session_data *sd = (struct map_session_data *) bl; + dumb_ptr<map_session_data> sd = bl->as_player(); if (sd->attacktarget == id && sd->attacktimer && sd->attacktarget_lv >= target_lv) (*c)++; } else if (bl->bl_type == BL::MOB) { - struct mob_data *md = (struct mob_data *) bl; + dumb_ptr<mob_data> md = bl->as_mob(); if (md->target_id == id && md->timer && md->state.state == MS::ATTACK && md->target_lv >= target_lv) @@ -386,7 +386,7 @@ void pc_counttargeted_sub(struct block_list *bl, } } -int pc_counttargeted(struct map_session_data *sd, struct block_list *src, +int pc_counttargeted(dumb_ptr<map_session_data> sd, dumb_ptr<block_list> src, ATK target_lv) { int c = 0; @@ -401,13 +401,13 @@ int pc_counttargeted(struct map_session_data *sd, struct block_list *src, *------------------------------------------ */ static -int pc_walktoxy_sub(struct map_session_data *); +int pc_walktoxy_sub(dumb_ptr<map_session_data>); /*========================================== * saveに必要なステータス修正を行なう *------------------------------------------ */ -int pc_makesavestatus(struct map_session_data *sd) +int pc_makesavestatus(dumb_ptr<map_session_data> sd) { nullpo_ret(sd); @@ -448,7 +448,7 @@ int pc_makesavestatus(struct map_session_data *sd) * 接続時の初期化 *------------------------------------------ */ -int pc_setnewpc(struct map_session_data *sd, int account_id, int char_id, +int pc_setnewpc(dumb_ptr<map_session_data> sd, int account_id, int char_id, int login_id1, tick_t client_tick, int sex) { nullpo_ret(sd); @@ -468,7 +468,7 @@ int pc_setnewpc(struct map_session_data *sd, int account_id, int char_id, return 0; } -EPOS pc_equippoint(struct map_session_data *sd, int n) +EPOS pc_equippoint(dumb_ptr<map_session_data> sd, int n) { nullpo_retr(EPOS::ZERO, sd); @@ -481,7 +481,7 @@ EPOS pc_equippoint(struct map_session_data *sd, int n) } static -int pc_setinventorydata(struct map_session_data *sd) +int pc_setinventorydata(dumb_ptr<map_session_data> sd) { int i, id; @@ -496,7 +496,7 @@ int pc_setinventorydata(struct map_session_data *sd) } static -int pc_calcweapontype(struct map_session_data *sd) +int pc_calcweapontype(dumb_ptr<map_session_data> sd) { nullpo_ret(sd); @@ -539,7 +539,7 @@ int pc_calcweapontype(struct map_session_data *sd) } static -int pc_setequipindex(struct map_session_data *sd) +int pc_setequipindex(dumb_ptr<map_session_data> sd) { nullpo_ret(sd); @@ -587,7 +587,7 @@ int pc_setequipindex(struct map_session_data *sd) } static -int pc_isequip(struct map_session_data *sd, int n) +int pc_isequip(dumb_ptr<map_session_data> sd, int n) { struct item_data *item; eptr<struct status_change, StatusChange> sc_data; @@ -623,7 +623,7 @@ int pc_isequip(struct map_session_data *sd, int n) int pc_authok(int id, int login_id2, TimeT connect_until_time, short tmw_version, const struct mmo_charstatus *st) { - struct map_session_data *sd = NULL; + dumb_ptr<map_session_data> sd = NULL; struct party *p; tick_t tick = gettick(); @@ -824,7 +824,7 @@ int pc_authok(int id, int login_id2, TimeT connect_until_time, */ int pc_authfail(int id) { - struct map_session_data *sd; + dumb_ptr<map_session_data> sd; sd = map_id2sd(id); if (sd == NULL) @@ -836,7 +836,7 @@ int pc_authfail(int id) } static -int pc_calc_skillpoint(struct map_session_data *sd) +int pc_calc_skillpoint(dumb_ptr<map_session_data> sd) { int i, skill_points = 0; @@ -855,7 +855,7 @@ int pc_calc_skillpoint(struct map_session_data *sd) * 重量アイコンの確認 *------------------------------------------ */ -int pc_checkweighticon(struct map_session_data *sd) +int pc_checkweighticon(dumb_ptr<map_session_data> sd) { int flag = 0; @@ -890,7 +890,7 @@ int pc_checkweighticon(struct map_session_data *sd) } static -void pc_set_weapon_look(struct map_session_data *sd) +void pc_set_weapon_look(dumb_ptr<map_session_data> sd) { if (sd->attack_spell_override) clif_changelook(sd, LOOK::WEAPON, @@ -907,7 +907,7 @@ void pc_set_weapon_look(struct map_session_data *sd) * 能動的に変化させたパラメータは自前でsendするように *------------------------------------------ */ -int pc_calcstatus(struct map_session_data *sd, int first) +int pc_calcstatus(dumb_ptr<map_session_data> sd, int first) { int b_max_hp, b_max_sp, b_hp, b_sp, b_weight, b_max_weight, b_hit, b_flee; @@ -1540,7 +1540,7 @@ int pc_calcstatus(struct map_session_data *sd, int first) * 装 備品による能力等のボーナス設定 *------------------------------------------ */ -int pc_bonus(struct map_session_data *sd, SP type, int val) +int pc_bonus(dumb_ptr<map_session_data> sd, SP type, int val) { nullpo_ret(sd); @@ -1805,7 +1805,7 @@ int pc_bonus(struct map_session_data *sd, SP type, int val) * ソスソス ソスソスソスiソスノゑソスソスソスソス\ソスヘ難ソスソスフボソス[ソスiソスXソスン抵ソス *------------------------------------------ */ -int pc_bonus2(struct map_session_data *sd, SP type, int type2, int val) +int pc_bonus2(dumb_ptr<map_session_data> sd, SP type, int type2, int val) { nullpo_ret(sd); @@ -1850,7 +1850,7 @@ int pc_bonus2(struct map_session_data *sd, SP type, int type2, int val) * スクリプトによるスキル所得 *------------------------------------------ */ -int pc_skill(struct map_session_data *sd, SkillID id, int level, int flag) +int pc_skill(dumb_ptr<map_session_data> sd, SkillID id, int level, int flag) { nullpo_ret(sd); @@ -1880,7 +1880,7 @@ int pc_skill(struct map_session_data *sd, SkillID id, int level, int flag) * 3万個制限にかかるか確認 *------------------------------------------ */ -ADDITEM pc_checkadditem(struct map_session_data *sd, int nameid, int amount) +ADDITEM pc_checkadditem(dumb_ptr<map_session_data> sd, int nameid, int amount) { int i; @@ -1908,7 +1908,7 @@ ADDITEM pc_checkadditem(struct map_session_data *sd, int nameid, int amount) * 空きアイテム欄の個数 *------------------------------------------ */ -int pc_inventoryblank(struct map_session_data *sd) +int pc_inventoryblank(dumb_ptr<map_session_data> sd) { int i, b; @@ -1927,7 +1927,7 @@ int pc_inventoryblank(struct map_session_data *sd) * お金を払う *------------------------------------------ */ -int pc_payzeny(struct map_session_data *sd, int zeny) +int pc_payzeny(dumb_ptr<map_session_data> sd, int zeny) { double z; @@ -1946,7 +1946,7 @@ int pc_payzeny(struct map_session_data *sd, int zeny) * お金を得る *------------------------------------------ */ -int pc_getzeny(struct map_session_data *sd, int zeny) +int pc_getzeny(dumb_ptr<map_session_data> sd, int zeny) { double z; @@ -1968,7 +1968,7 @@ int pc_getzeny(struct map_session_data *sd, int zeny) * アイテムを探して、インデックスを返す *------------------------------------------ */ -int pc_search_inventory(struct map_session_data *sd, int item_id) +int pc_search_inventory(dumb_ptr<map_session_data> sd, int item_id) { int i; @@ -1984,7 +1984,7 @@ int pc_search_inventory(struct map_session_data *sd, int item_id) return -1; } -int pc_count_all_items(struct map_session_data *player, int item_id) +int pc_count_all_items(dumb_ptr<map_session_data> player, int item_id) { int i; int count = 0; @@ -2000,7 +2000,7 @@ int pc_count_all_items(struct map_session_data *player, int item_id) return count; } -int pc_remove_items(struct map_session_data *player, int item_id, int count) +int pc_remove_items(dumb_ptr<map_session_data> player, int item_id, int count) { int i; @@ -2031,7 +2031,7 @@ int pc_remove_items(struct map_session_data *player, int item_id, int count) * アイテム追加。個数のみitem構造体の数字を無視 *------------------------------------------ */ -PickupFail pc_additem(struct map_session_data *sd, struct item *item_data, +PickupFail pc_additem(dumb_ptr<map_session_data> sd, struct item *item_data, int amount) { struct item_data *data; @@ -2096,7 +2096,7 @@ PickupFail pc_additem(struct map_session_data *sd, struct item *item_data, * アイテムを減らす *------------------------------------------ */ -int pc_delitem(struct map_session_data *sd, int n, int amount, int type) +int pc_delitem(dumb_ptr<map_session_data> sd, int n, int amount, int type) { nullpo_retr(1, sd); @@ -2130,7 +2130,7 @@ int pc_delitem(struct map_session_data *sd, int n, int amount, int type) * アイテムを落す *------------------------------------------ */ -int pc_dropitem(struct map_session_data *sd, int n, int amount) +int pc_dropitem(dumb_ptr<map_session_data> sd, int n, int amount) { nullpo_retr(1, sd); @@ -2163,7 +2163,7 @@ int pc_dropitem(struct map_session_data *sd, int n, int amount) */ static -int can_pick_item_up_from(struct map_session_data *self, int other_id) +int can_pick_item_up_from(dumb_ptr<map_session_data> self, int other_id) { struct party *p = party_search(self->status.party_id); @@ -2171,7 +2171,7 @@ int can_pick_item_up_from(struct map_session_data *self, int other_id) if (!self || self->bl_id == other_id || !other_id) return 1; - struct map_session_data *other = map_id2sd(other_id); + dumb_ptr<map_session_data> other = map_id2sd(other_id); /* Other no longer exists? */ if (!other) @@ -2201,7 +2201,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) +int pc_takeitem(dumb_ptr<map_session_data> sd, dumb_ptr<flooritem_data> fitem) { tick_t tick = gettick(); int can_take; @@ -2258,7 +2258,7 @@ int pc_takeitem(struct map_session_data *sd, struct flooritem_data *fitem) } static -int pc_isUseitem(struct map_session_data *sd, int n) +int pc_isUseitem(dumb_ptr<map_session_data> sd, int n) { struct item_data *item; int nameid; @@ -2295,7 +2295,7 @@ int pc_isUseitem(struct map_session_data *sd, int n) * アイテムを使う *------------------------------------------ */ -int pc_useitem(struct map_session_data *sd, int n) +int pc_useitem(dumb_ptr<map_session_data> sd, int n) { int amount; @@ -2326,7 +2326,7 @@ int pc_useitem(struct map_session_data *sd, int n) *------------------------------------------ */ static -int pc_cart_delitem(struct map_session_data *sd, int n, int amount, int) +int pc_cart_delitem(dumb_ptr<map_session_data> sd, int n, int amount, int) { nullpo_retr(1, sd); @@ -2351,7 +2351,7 @@ int pc_cart_delitem(struct map_session_data *sd, int n, int amount, int) * PCの位置設定 *------------------------------------------ */ -int pc_setpos(struct map_session_data *sd, const char *mapname_org, int x, int y, +int pc_setpos(dumb_ptr<map_session_data> sd, const char *mapname_org, int x, int y, BeingRemoveWhy clrtype) { char mapname[24]; @@ -2465,7 +2465,7 @@ int pc_setpos(struct map_session_data *sd, const char *mapname_org, int x, int y * PCのランダムワープ *------------------------------------------ */ -int pc_randomwarp(struct map_session_data *sd, BeingRemoveWhy type) +int pc_randomwarp(dumb_ptr<map_session_data> sd, BeingRemoveWhy type) { int x, y, i = 0; int m; @@ -2496,7 +2496,7 @@ int pc_randomwarp(struct map_session_data *sd, BeingRemoveWhy type) *------------------------------------------ */ static -int pc_can_reach(struct map_session_data *sd, int x, int y) +int pc_can_reach(dumb_ptr<map_session_data> sd, int x, int y) { struct walkpath_data wpd; @@ -2521,7 +2521,7 @@ int pc_can_reach(struct map_session_data *sd, int x, int y) *------------------------------------------ */ static -interval_t calc_next_walk_step(struct map_session_data *sd) +interval_t calc_next_walk_step(dumb_ptr<map_session_data> sd) { nullpo_retr(interval_t::zero(), sd); @@ -2540,7 +2540,7 @@ interval_t calc_next_walk_step(struct map_session_data *sd) static void pc_walk(TimerData *, tick_t tick, int id, unsigned char data) { - struct map_session_data *sd; + dumb_ptr<map_session_data> sd; int moveblock; int x, y, dx, dy; @@ -2658,7 +2658,7 @@ void pc_walk(TimerData *, tick_t tick, int id, unsigned char data) *------------------------------------------ */ static -int pc_walktoxy_sub(struct map_session_data *sd) +int pc_walktoxy_sub(dumb_ptr<map_session_data> sd) { struct walkpath_data wpd; @@ -2688,7 +2688,7 @@ int pc_walktoxy_sub(struct map_session_data *sd) * pc歩 行要求 *------------------------------------------ */ -int pc_walktoxy(struct map_session_data *sd, int x, int y) +int pc_walktoxy(dumb_ptr<map_session_data> sd, int x, int y) { nullpo_ret(sd); @@ -2717,7 +2717,7 @@ int pc_walktoxy(struct map_session_data *sd, int x, int y) * 歩 行停止 *------------------------------------------ */ -int pc_stop_walking(struct map_session_data *sd, int type) +int pc_stop_walking(dumb_ptr<map_session_data> sd, int type) { nullpo_ret(sd); @@ -2739,7 +2739,7 @@ int pc_stop_walking(struct map_session_data *sd, int type) return 0; } -void pc_touch_all_relevant_npcs(struct map_session_data *sd) +void pc_touch_all_relevant_npcs(dumb_ptr<map_session_data> sd) { if (bool(map_getcell(sd->bl_m, sd->bl_x, sd->bl_y) & MapCell::NPC_NEAR)) npc_touch_areanpc(sd, sd->bl_m, sd->bl_x, sd->bl_y); @@ -2751,7 +2751,7 @@ void pc_touch_all_relevant_npcs(struct map_session_data *sd) * *------------------------------------------ */ -int pc_movepos(struct map_session_data *sd, int dst_x, int dst_y) +int pc_movepos(dumb_ptr<map_session_data> sd, int dst_x, int dst_y) { int moveblock; int dx, dy; @@ -2817,7 +2817,7 @@ int pc_movepos(struct map_session_data *sd, int dst_x, int dst_y) * スキルの検索 所有していた場合Lvが返る *------------------------------------------ */ -int pc_checkskill(struct map_session_data *sd, SkillID skill_id) +int pc_checkskill(dumb_ptr<map_session_data> sd, SkillID skill_id) { if (sd == NULL) return 0; @@ -2829,7 +2829,7 @@ int pc_checkskill(struct map_session_data *sd, SkillID skill_id) * 装 備品のチェック *------------------------------------------ */ -int pc_checkequip(struct map_session_data *sd, EPOS pos) +int pc_checkequip(dumb_ptr<map_session_data> sd, EPOS pos) { nullpo_retr(-1, sd); @@ -2849,8 +2849,8 @@ int pc_checkequip(struct map_session_data *sd, EPOS pos) static void pc_attack_timer(TimerData *, tick_t tick, int id) { - struct map_session_data *sd; - struct block_list *bl; + dumb_ptr<map_session_data> sd; + dumb_ptr<block_list> bl; eptr<struct status_change, StatusChange> sc_data; int dist, range; @@ -2865,7 +2865,7 @@ void pc_attack_timer(TimerData *, tick_t tick, int id) if (bl == NULL || bl->bl_prev == NULL) return; - if (bl->bl_type == BL::PC && pc_isdead((struct map_session_data *) bl)) + if (bl->bl_type == BL::PC && pc_isdead(bl->as_player())) return; // 同じmapでないなら攻撃しない @@ -2954,9 +2954,9 @@ void pc_attack_timer(TimerData *, tick_t tick, int id) * typeが1なら継続攻撃 *------------------------------------------ */ -int pc_attack(struct map_session_data *sd, int target_id, int type) +int pc_attack(dumb_ptr<map_session_data> sd, int target_id, int type) { - struct block_list *bl; + dumb_ptr<block_list> bl; nullpo_ret(sd); @@ -2997,7 +2997,7 @@ int pc_attack(struct map_session_data *sd, int target_id, int type) * 継続攻撃停止 *------------------------------------------ */ -int pc_stopattack(struct map_session_data *sd) +int pc_stopattack(dumb_ptr<map_session_data> sd) { nullpo_ret(sd); @@ -3010,7 +3010,7 @@ int pc_stopattack(struct map_session_data *sd) } static -int pc_checkbaselevelup(struct map_session_data *sd) +int pc_checkbaselevelup(dumb_ptr<map_session_data> sd) { int next = pc_nextbaseexp(sd); @@ -3051,7 +3051,7 @@ int RAISE_COST(int x) *---------------------------------------- */ static -int pc_skillpt_potential(struct map_session_data *sd) +int pc_skillpt_potential(dumb_ptr<map_session_data> sd) { int potential = 0; @@ -3066,7 +3066,7 @@ int pc_skillpt_potential(struct map_session_data *sd) } static -int pc_checkjoblevelup(struct map_session_data *sd) +int pc_checkjoblevelup(dumb_ptr<map_session_data> sd) { int next = pc_nextjobexp(sd); @@ -3102,7 +3102,7 @@ int pc_checkjoblevelup(struct map_session_data *sd) return 0; } -int pc_gainexp_reason(struct map_session_data *sd, int base_exp, int job_exp, +int pc_gainexp_reason(dumb_ptr<map_session_data> sd, int base_exp, int job_exp, PC_GAINEXP_REASON reason) { nullpo_ret(sd); @@ -3182,7 +3182,7 @@ int pc_gainexp_reason(struct map_session_data *sd, int base_exp, int job_exp, return 0; } -int pc_extract_healer_exp(struct map_session_data *sd, int max) +int pc_extract_healer_exp(dumb_ptr<map_session_data> sd, int max) { int amount; nullpo_ret(sd); @@ -3199,7 +3199,7 @@ int pc_extract_healer_exp(struct map_session_data *sd, int max) * base level側必要経験値計算 *------------------------------------------ */ -int pc_nextbaseexp(struct map_session_data *sd) +int pc_nextbaseexp(dumb_ptr<map_session_data> sd) { nullpo_ret(sd); @@ -3213,7 +3213,7 @@ int pc_nextbaseexp(struct map_session_data *sd) * job level側必要経験値計算 *------------------------------------------ */ -int pc_nextjobexp(struct map_session_data *sd) +int pc_nextjobexp(dumb_ptr<map_session_data> sd) { // [fate] For normal levels, this ranges from 20k to 50k, depending on job level. // Job level is at most twice the player's experience level (base_level). Levelling @@ -3227,7 +3227,7 @@ int pc_nextjobexp(struct map_session_data *sd) * base level after next [Valaris] *------------------------------------------ */ -int pc_nextbaseafter(struct map_session_data *sd) +int pc_nextbaseafter(dumb_ptr<map_session_data> sd) { nullpo_ret(sd); @@ -3241,7 +3241,7 @@ int pc_nextbaseafter(struct map_session_data *sd) * job level after next [Valaris] *------------------------------------------ */ -int pc_nextjobafter(struct map_session_data *sd) +int pc_nextjobafter(dumb_ptr<map_session_data> sd) { nullpo_ret(sd); @@ -3256,7 +3256,7 @@ int pc_nextjobafter(struct map_session_data *sd) *------------------------------------------ */ // TODO: replace SP by ATTR -int pc_need_status_point(struct map_session_data *sd, SP type) +int pc_need_status_point(dumb_ptr<map_session_data> sd, SP type) { int val; @@ -3273,7 +3273,7 @@ int pc_need_status_point(struct map_session_data *sd, SP type) * 能力値成長 *------------------------------------------ */ -int pc_statusup(struct map_session_data *sd, SP type) +int pc_statusup(dumb_ptr<map_session_data> sd, SP type) { int need, val = 0; @@ -3311,7 +3311,7 @@ int pc_statusup(struct map_session_data *sd, SP type) * 能力値成長 *------------------------------------------ */ -int pc_statusup2(struct map_session_data *sd, SP type, int val) +int pc_statusup2(dumb_ptr<map_session_data> sd, SP type, int val) { nullpo_ret(sd); @@ -3337,7 +3337,7 @@ int pc_statusup2(struct map_session_data *sd, SP type, int val) * スキルポイント割り振り *------------------------------------------ */ -int pc_skillup(struct map_session_data *sd, SkillID skill_num) +int pc_skillup(dumb_ptr<map_session_data> sd, SkillID skill_num) { nullpo_ret(sd); @@ -3364,7 +3364,7 @@ int pc_skillup(struct map_session_data *sd, SkillID skill_num) * /resetlvl *------------------------------------------ */ -int pc_resetlvl(struct map_session_data *sd, int type) +int pc_resetlvl(dumb_ptr<map_session_data> sd, int type) { nullpo_ret(sd); @@ -3449,7 +3449,7 @@ int pc_resetlvl(struct map_session_data *sd, int type) * /resetstate *------------------------------------------ */ -int pc_resetstate(struct map_session_data *sd) +int pc_resetstate(dumb_ptr<map_session_data> sd) { nullpo_ret(sd); @@ -3474,7 +3474,7 @@ int pc_resetstate(struct map_session_data *sd) * /resetskill *------------------------------------------ */ -int pc_resetskill(struct map_session_data *sd) +int pc_resetskill(dumb_ptr<map_session_data> sd) { int skill; @@ -3500,7 +3500,7 @@ int pc_resetskill(struct map_session_data *sd) * pcにダメージを与える *------------------------------------------ */ -int pc_damage(struct block_list *src, struct map_session_data *sd, +int pc_damage(dumb_ptr<block_list> src, dumb_ptr<map_session_data> sd, int damage) { int i = 0; @@ -3522,7 +3522,7 @@ int pc_damage(struct block_list *src, struct map_session_data *sd, if (src->bl_type == BL::PC) { MAP_LOG_PC(sd, "INJURED-BY PC%d FOR %d", - ((struct map_session_data *) src)->status.char_id, + src->as_player()->status.char_id, damage); } else @@ -3650,8 +3650,7 @@ int pc_damage(struct block_list *src, struct map_session_data *sd, { sd->pvp_point -= 5; if (src && src->bl_type == BL::PC) - ((struct map_session_data *) src)->pvp_point++; - //} //fixed wrong '{' placement by Lupus + src->as_player()->pvp_point++; pc_setdead(sd); } // 強制送還 @@ -3690,7 +3689,7 @@ int pc_damage(struct block_list *src, struct map_session_data *sd, * script用PCステータス読み出し *------------------------------------------ */ -int pc_readparam(struct map_session_data *sd, SP type) +int pc_readparam(dumb_ptr<map_session_data> sd, SP type) { int val = 0; @@ -3766,7 +3765,7 @@ int pc_readparam(struct map_session_data *sd, SP type) * script用PCステータス設定 *------------------------------------------ */ -int pc_setparam(struct map_session_data *sd, SP type, int val) +int pc_setparam(dumb_ptr<map_session_data> sd, SP type, int val) { int i = 0, up_level = 50; @@ -3883,7 +3882,7 @@ int pc_setparam(struct map_session_data *sd, SP type, int val) * HP/SP回復 *------------------------------------------ */ -int pc_heal(struct map_session_data *sd, int hp, int sp) +int pc_heal(dumb_ptr<map_session_data> sd, int hp, int sp) { // if(battle_config.battle_log) // PRINTF("heal %d %d\n",hp,sp); @@ -3935,7 +3934,7 @@ int pc_heal(struct map_session_data *sd, int hp, int sp) *------------------------------------------ */ static -int pc_itemheal_effect(struct map_session_data *sd, int hp, int sp); +int pc_itemheal_effect(dumb_ptr<map_session_data> sd, int hp, int sp); static int // Compute how quickly we regenerate (less is faster) for that amount @@ -3975,7 +3974,7 @@ void pc_heal_quick_accumulate(int new_amount, quick_regen->tickdelay = min(quick_regen->speed, quick_regen->tickdelay); } -int pc_itemheal(struct map_session_data *sd, int hp, int sp) +int pc_itemheal(dumb_ptr<map_session_data> sd, int hp, int sp) { /* defer healing */ if (hp > 0) @@ -4005,7 +4004,7 @@ int pc_itemheal(struct map_session_data *sd, int hp, int sp) * has health recovery queued up (cf. pc_natural_heal_sub). */ static -int pc_itemheal_effect(struct map_session_data *sd, int hp, int sp) +int pc_itemheal_effect(dumb_ptr<map_session_data> sd, int hp, int sp) { nullpo_ret(sd); @@ -4055,7 +4054,7 @@ int pc_itemheal_effect(struct map_session_data *sd, int hp, int sp) * HP/SP回復 *------------------------------------------ */ -int pc_percentheal(struct map_session_data *sd, int hp, int sp) +int pc_percentheal(dumb_ptr<map_session_data> sd, int hp, int sp) { nullpo_ret(sd); @@ -4124,7 +4123,7 @@ int pc_percentheal(struct map_session_data *sd, int hp, int sp) * 見た目変更 *------------------------------------------ */ -int pc_changelook(struct map_session_data *sd, LOOK type, int val) +int pc_changelook(dumb_ptr<map_session_data> sd, LOOK type, int val) { nullpo_ret(sd); @@ -4166,7 +4165,7 @@ int pc_changelook(struct map_session_data *sd, LOOK type, int val) * 付属品(鷹,ペコ,カート)設定 *------------------------------------------ */ -int pc_setoption(struct map_session_data *sd, Option type) +int pc_setoption(dumb_ptr<map_session_data> sd, Option type) { nullpo_ret(sd); @@ -4181,7 +4180,7 @@ int pc_setoption(struct map_session_data *sd, Option type) * script用変数の値を読む *------------------------------------------ */ -int pc_readreg(struct map_session_data *sd, int reg) +int pc_readreg(dumb_ptr<map_session_data> sd, int reg) { int i; @@ -4198,7 +4197,7 @@ int pc_readreg(struct map_session_data *sd, int reg) * script用変数の値を設定 *------------------------------------------ */ -int pc_setreg(struct map_session_data *sd, int reg, int val) +int pc_setreg(dumb_ptr<map_session_data> sd, int reg, int val) { int i; @@ -4224,7 +4223,7 @@ int pc_setreg(struct map_session_data *sd, int reg, int val) * script用文字列変数の値を読む *------------------------------------------ */ -char *pc_readregstr(struct map_session_data *sd, int reg) +char *pc_readregstr(dumb_ptr<map_session_data> sd, int reg) { int i; @@ -4241,7 +4240,7 @@ char *pc_readregstr(struct map_session_data *sd, int reg) * script用文字列変数の値を設定 *------------------------------------------ */ -int pc_setregstr(struct map_session_data *sd, int reg, const char *str) +int pc_setregstr(dumb_ptr<map_session_data> sd, int reg, const char *str) { int i; @@ -4271,7 +4270,7 @@ int pc_setregstr(struct map_session_data *sd, int reg, const char *str) * script用グローバル変数の値を読む *------------------------------------------ */ -int pc_readglobalreg(struct map_session_data *sd, const char *reg) +int pc_readglobalreg(dumb_ptr<map_session_data> sd, const char *reg) { int i; @@ -4290,7 +4289,7 @@ int pc_readglobalreg(struct map_session_data *sd, const char *reg) * script用グローバル変数の値を設定 *------------------------------------------ */ -int pc_setglobalreg(struct map_session_data *sd, const char *reg, int val) +int pc_setglobalreg(dumb_ptr<map_session_data> sd, const char *reg, int val) { int i; @@ -4342,7 +4341,7 @@ int pc_setglobalreg(struct map_session_data *sd, const char *reg, int val) * script用アカウント変数の値を読む *------------------------------------------ */ -int pc_readaccountreg(struct map_session_data *sd, const char *reg) +int pc_readaccountreg(dumb_ptr<map_session_data> sd, const char *reg) { int i; @@ -4361,7 +4360,7 @@ int pc_readaccountreg(struct map_session_data *sd, const char *reg) * script用アカウント変数の値を設定 *------------------------------------------ */ -int pc_setaccountreg(struct map_session_data *sd, const char *reg, int val) +int pc_setaccountreg(dumb_ptr<map_session_data> sd, const char *reg, int val) { int i; @@ -4410,7 +4409,7 @@ int pc_setaccountreg(struct map_session_data *sd, const char *reg, int val) * script用アカウント変数2の値を読む *------------------------------------------ */ -int pc_readaccountreg2(struct map_session_data *sd, const char *reg) +int pc_readaccountreg2(dumb_ptr<map_session_data> sd, const char *reg) { int i; @@ -4429,7 +4428,7 @@ int pc_readaccountreg2(struct map_session_data *sd, const char *reg) * script用アカウント変数2の値を設定 *------------------------------------------ */ -int pc_setaccountreg2(struct map_session_data *sd, const char *reg, int val) +int pc_setaccountreg2(dumb_ptr<map_session_data> sd, const char *reg, int val) { int i; @@ -4481,7 +4480,7 @@ int pc_setaccountreg2(struct map_session_data *sd, const char *reg, int val) static void pc_eventtimer(TimerData *, tick_t, int id, const char *data) { - struct map_session_data *sd = map_id2sd(id); + dumb_ptr<map_session_data> sd = map_id2sd(id); assert (sd != NULL); npc_event(sd, data, 0); @@ -4493,7 +4492,7 @@ void pc_eventtimer(TimerData *, tick_t, int id, const char *data) * イベントタイマー追加 *------------------------------------------ */ -int pc_addeventtimer(struct map_session_data *sd, interval_t tick, const char *name) +int pc_addeventtimer(dumb_ptr<map_session_data> sd, interval_t tick, const char *name) { int i; @@ -4520,7 +4519,7 @@ int pc_addeventtimer(struct map_session_data *sd, interval_t tick, const char *n * イベントタイマー全削除 *------------------------------------------ */ -int pc_cleareventtimer(struct map_session_data *sd) +int pc_cleareventtimer(dumb_ptr<map_session_data> sd) { nullpo_ret(sd); @@ -4538,7 +4537,7 @@ int pc_cleareventtimer(struct map_session_data *sd) *------------------------------------------ */ static -int pc_signal_advanced_equipment_change(struct map_session_data *sd, int n) +int pc_signal_advanced_equipment_change(dumb_ptr<map_session_data> sd, int n) { if (bool(sd->status.inventory[n].equip & EPOS::SHOES)) clif_changelook(sd, LOOK::SHOES, 0); @@ -4553,7 +4552,7 @@ int pc_signal_advanced_equipment_change(struct map_session_data *sd, int n) return 0; } -int pc_equipitem(struct map_session_data *sd, int n, EPOS) +int pc_equipitem(dumb_ptr<map_session_data> sd, int n, EPOS) { int nameid; struct item_data *id; @@ -4696,7 +4695,7 @@ int pc_equipitem(struct map_session_data *sd, int n, EPOS) * 装 備した物を外す *------------------------------------------ */ -int pc_unequipitem(struct map_session_data *sd, int n, CalcStatus type) +int pc_unequipitem(dumb_ptr<map_session_data> sd, int n, CalcStatus type) { nullpo_ret(sd); @@ -4765,7 +4764,7 @@ int pc_unequipitem(struct map_session_data *sd, int n, CalcStatus type) return 0; } -int pc_unequipinvyitem(struct map_session_data *sd, int n, CalcStatus type) +int pc_unequipinvyitem(dumb_ptr<map_session_data> sd, int n, CalcStatus type) { nullpo_retr(1, sd); @@ -4789,7 +4788,7 @@ int pc_unequipinvyitem(struct map_session_data *sd, int n, CalcStatus type) * 装 備品の装備可能チェックを行なう *------------------------------------------ */ -int pc_checkitem(struct map_session_data *sd) +int pc_checkitem(dumb_ptr<map_session_data> sd) { int i, j, k, id, calc_flag = 0; struct item_data *it = NULL; @@ -4878,7 +4877,7 @@ int pc_checkitem(struct map_session_data *sd) return 0; } -int pc_checkoverhp(struct map_session_data *sd) +int pc_checkoverhp(dumb_ptr<map_session_data> sd) { nullpo_ret(sd); @@ -4894,7 +4893,7 @@ int pc_checkoverhp(struct map_session_data *sd) return 0; } -int pc_checkoversp(struct map_session_data *sd) +int pc_checkoversp(dumb_ptr<map_session_data> sd) { nullpo_ret(sd); @@ -4915,12 +4914,12 @@ int pc_checkoversp(struct map_session_data *sd) *------------------------------------------ */ static -void pc_calc_pvprank_sub(struct block_list *bl, struct map_session_data *sd2) +void pc_calc_pvprank_sub(dumb_ptr<block_list> bl, dumb_ptr<map_session_data> sd2) { - struct map_session_data *sd1; + dumb_ptr<map_session_data> sd1; nullpo_retv(bl); - sd1 = (struct map_session_data *) bl; + sd1 = bl->as_player(); nullpo_retv(sd2); if (sd1->pvp_point > sd2->pvp_point) @@ -4931,7 +4930,7 @@ void pc_calc_pvprank_sub(struct block_list *bl, struct map_session_data *sd2) * PVP順位計算 *------------------------------------------ */ -int pc_calc_pvprank(struct map_session_data *sd) +int pc_calc_pvprank(dumb_ptr<map_session_data> sd) { struct map_data *m; @@ -4954,7 +4953,7 @@ int pc_calc_pvprank(struct map_session_data *sd) */ void pc_calc_pvprank_timer(TimerData *, tick_t, int id) { - struct map_session_data *sd = NULL; + dumb_ptr<map_session_data> sd = NULL; if (battle_config.pk_mode) // disable pvp ranking if pk_mode on [Valaris] return; @@ -4973,7 +4972,7 @@ void pc_calc_pvprank_timer(TimerData *, tick_t, int id) *------------------------------------------ */ static -int pc_ismarried(struct map_session_data *sd) +int pc_ismarried(dumb_ptr<map_session_data> sd) { if (sd == NULL) return -1; @@ -4987,7 +4986,7 @@ int pc_ismarried(struct map_session_data *sd) * sdがdstsdと結婚(dstsd→sdの結婚処理も同時に行う) *------------------------------------------ */ -int pc_marriage(struct map_session_data *sd, struct map_session_data *dstsd) +int pc_marriage(dumb_ptr<map_session_data> sd, dumb_ptr<map_session_data> dstsd) { if (sd == NULL || dstsd == NULL || sd->status.partner_id > 0 || dstsd->status.partner_id > 0) @@ -5001,9 +5000,9 @@ int pc_marriage(struct map_session_data *sd, struct map_session_data *dstsd) * sdが離婚(相手はsd->status.partner_idに依る)(相手も同時に離婚・結婚指輪自動剥奪) *------------------------------------------ */ -int pc_divorce(struct map_session_data *sd) +int pc_divorce(dumb_ptr<map_session_data> sd) { - struct map_session_data *p_sd = NULL; + dumb_ptr<map_session_data> p_sd = NULL; if (sd == NULL || !pc_ismarried(sd)) return -1; @@ -5037,9 +5036,9 @@ int pc_divorce(struct map_session_data *sd) * sdの相方のmap_session_dataを返す *------------------------------------------ */ -struct map_session_data *pc_get_partner(struct map_session_data *sd) +dumb_ptr<map_session_data> pc_get_partner(dumb_ptr<map_session_data> sd) { - struct map_session_data *p_sd = NULL; + dumb_ptr<map_session_data> p_sd = NULL; char *nick; if (sd == NULL || !pc_ismarried(sd)) return NULL; @@ -5068,7 +5067,7 @@ static interval_t natural_heal_diff_tick; static -interval_t pc_spheal(struct map_session_data *sd) +interval_t pc_spheal(dumb_ptr<map_session_data> sd) { nullpo_retr(interval_t::zero(), sd); @@ -5084,7 +5083,7 @@ interval_t pc_spheal(struct map_session_data *sd) *------------------------------------------ */ static -interval_t pc_hpheal(struct map_session_data *sd) +interval_t pc_hpheal(dumb_ptr<map_session_data> sd) { nullpo_retr(interval_t::zero(), sd); @@ -5096,7 +5095,7 @@ interval_t pc_hpheal(struct map_session_data *sd) } static -int pc_natural_heal_hp(struct map_session_data *sd) +int pc_natural_heal_hp(dumb_ptr<map_session_data> sd) { int bhp; int bonus; @@ -5168,7 +5167,7 @@ int pc_natural_heal_hp(struct map_session_data *sd) } static -int pc_natural_heal_sp(struct map_session_data *sd) +int pc_natural_heal_sp(dumb_ptr<map_session_data> sd) { int bsp; int bonus; @@ -5260,7 +5259,7 @@ int pc_quickregenerate_effect(struct quick_regeneration *quick_regen, } static -void pc_natural_heal_sub(struct map_session_data *sd) +void pc_natural_heal_sub(dumb_ptr<map_session_data> sd) { nullpo_retv(sd); @@ -5338,7 +5337,7 @@ void pc_natural_heal(TimerData *, tick_t tick) * セーブポイントの保存 *------------------------------------------ */ -int pc_setsavepoint(struct map_session_data *sd, const char *mapname, int x, int y) +int pc_setsavepoint(dumb_ptr<map_session_data> sd, const char *mapname, int x, int y) { nullpo_ret(sd); @@ -5357,7 +5356,7 @@ int pc_setsavepoint(struct map_session_data *sd, const char *mapname, int x, int static int last_save_fd, save_flag; static -void pc_autosave_sub(struct map_session_data *sd) +void pc_autosave_sub(dumb_ptr<map_session_data> sd) { nullpo_retv(sd); @@ -5408,7 +5407,7 @@ int pc_read_gm_account(int fd) return GM_num; } -void pc_setstand(struct map_session_data *sd) +void pc_setstand(dumb_ptr<map_session_data> sd) { nullpo_retv(sd); @@ -5451,12 +5450,12 @@ int do_init_pc(void) return 0; } -void pc_cleanup(struct map_session_data *sd) +void pc_cleanup(dumb_ptr<map_session_data> sd) { magic_stop_completely(sd); } -void pc_invisibility(struct map_session_data *sd, int enabled) +void pc_invisibility(dumb_ptr<map_session_data> sd, int enabled) { if (enabled && !bool(sd->status.option & Option::INVISIBILITY)) { @@ -5472,7 +5471,7 @@ void pc_invisibility(struct map_session_data *sd, int enabled) } } -int pc_logout(struct map_session_data *sd) // [fate] Player logs out +int pc_logout(dumb_ptr<map_session_data> sd) // [fate] Player logs out { if (!sd) return 0; diff --git a/src/map/pc.hpp b/src/map/pc.hpp index 1f2ab71..4fa0b0c 100644 --- a/src/map/pc.hpp +++ b/src/map/pc.hpp @@ -7,147 +7,147 @@ #include "map.hpp" inline -void pc_setsit(struct map_session_data *sd) +void pc_setsit(dumb_ptr<map_session_data> sd) { sd->state.dead_sit = 2; } -//pc_setstand(struct map_session_data *sd) is a normal function +//pc_setstand(dumb_ptr<map_session_data> sd) is a normal function inline -bool pc_isdead(struct map_session_data *sd) +bool pc_isdead(dumb_ptr<map_session_data> sd) { return sd->state.dead_sit == 1; } inline -bool pc_issit(struct map_session_data *sd) +bool pc_issit(dumb_ptr<map_session_data> sd) { return sd->state.dead_sit == 2; } inline -void pc_setdir(struct map_session_data *sd, DIR b) +void pc_setdir(dumb_ptr<map_session_data> sd, DIR b) { sd->dir = (b); } inline -bool pc_isinvisible(struct map_session_data *sd) +bool pc_isinvisible(dumb_ptr<map_session_data> sd) { return bool(sd->status.option & Option::HIDE); } inline -bool pc_is90overweight(struct map_session_data *sd) +bool pc_is90overweight(dumb_ptr<map_session_data> sd) { return sd->weight*10 >= sd->max_weight*9; } // Checks all npcs/warps at the same location to see whether they // should do something with the specified player. -void pc_touch_all_relevant_npcs(struct map_session_data *sd); +void pc_touch_all_relevant_npcs(dumb_ptr<map_session_data> sd); -int pc_isGM(struct map_session_data *sd); -int pc_iskiller(struct map_session_data *src, struct map_session_data *target); // [MouseJstr] +int pc_isGM(dumb_ptr<map_session_data> sd); +int pc_iskiller(dumb_ptr<map_session_data> src, dumb_ptr<map_session_data> target); // [MouseJstr] -void pc_invisibility(struct map_session_data *sd, int enabled); // [Fate] -int pc_counttargeted(struct map_session_data *sd, struct block_list *src, +void pc_invisibility(dumb_ptr<map_session_data> sd, int enabled); // [Fate] +int pc_counttargeted(dumb_ptr<map_session_data> sd, dumb_ptr<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, tick_t, int); +int pc_setrestartvalue(dumb_ptr<map_session_data> sd, int type); +int pc_makesavestatus(dumb_ptr<map_session_data>); +int pc_setnewpc(dumb_ptr<map_session_data>, int, int, int, tick_t, int); int pc_authok(int, int, TimeT, short tmw_version, const struct mmo_charstatus *); int pc_authfail(int); -EPOS pc_equippoint(struct map_session_data *sd, int n); - -int pc_checkskill(struct map_session_data *sd, SkillID skill_id); -int pc_checkequip(struct map_session_data *sd, EPOS pos); - -int pc_walktoxy(struct map_session_data *, int, int); -int pc_stop_walking(struct map_session_data *, int); -int pc_movepos(struct map_session_data *, int, int); -int pc_setpos(struct map_session_data *, const char *, int, int, BeingRemoveWhy); -int pc_setsavepoint(struct map_session_data *, const char *, int, int); -int pc_randomwarp(struct map_session_data *sd, BeingRemoveWhy type); - -ADDITEM pc_checkadditem(struct map_session_data *, int, int); -int pc_inventoryblank(struct map_session_data *); -int pc_search_inventory(struct map_session_data *sd, int item_id); -int pc_payzeny(struct map_session_data *, int); -PickupFail pc_additem(struct map_session_data *, struct item *, int); -int pc_getzeny(struct map_session_data *, int); -int pc_delitem(struct map_session_data *, int, int, int); -int pc_checkitem(struct map_session_data *); -int pc_count_all_items(struct map_session_data *player, int item_id); -int pc_remove_items(struct map_session_data *player, +EPOS pc_equippoint(dumb_ptr<map_session_data> sd, int n); + +int pc_checkskill(dumb_ptr<map_session_data> sd, SkillID skill_id); +int pc_checkequip(dumb_ptr<map_session_data> sd, EPOS pos); + +int pc_walktoxy(dumb_ptr<map_session_data>, int, int); +int pc_stop_walking(dumb_ptr<map_session_data>, int); +int pc_movepos(dumb_ptr<map_session_data>, int, int); +int pc_setpos(dumb_ptr<map_session_data>, const char *, int, int, BeingRemoveWhy); +int pc_setsavepoint(dumb_ptr<map_session_data>, const char *, int, int); +int pc_randomwarp(dumb_ptr<map_session_data> sd, BeingRemoveWhy type); + +ADDITEM pc_checkadditem(dumb_ptr<map_session_data>, int, int); +int pc_inventoryblank(dumb_ptr<map_session_data>); +int pc_search_inventory(dumb_ptr<map_session_data> sd, int item_id); +int pc_payzeny(dumb_ptr<map_session_data>, int); +PickupFail pc_additem(dumb_ptr<map_session_data>, struct item *, int); +int pc_getzeny(dumb_ptr<map_session_data>, int); +int pc_delitem(dumb_ptr<map_session_data>, int, int, int); +int pc_checkitem(dumb_ptr<map_session_data>); +int pc_count_all_items(dumb_ptr<map_session_data> player, int item_id); +int pc_remove_items(dumb_ptr<map_session_data> player, int item_id, int count); -int pc_takeitem(struct map_session_data *, struct flooritem_data *); -int pc_dropitem(struct map_session_data *, int, int); +int pc_takeitem(dumb_ptr<map_session_data>, dumb_ptr<flooritem_data>); +int pc_dropitem(dumb_ptr<map_session_data>, int, int); -int pc_checkweighticon(struct map_session_data *sd); +int pc_checkweighticon(dumb_ptr<map_session_data> sd); -int pc_calcstatus(struct map_session_data *, int); -int pc_bonus(struct map_session_data *, SP, int); -int pc_bonus2(struct map_session_data *sd, SP, int, int); -int pc_skill(struct map_session_data *, SkillID, int, int); +int pc_calcstatus(dumb_ptr<map_session_data>, int); +int pc_bonus(dumb_ptr<map_session_data>, SP, int); +int pc_bonus2(dumb_ptr<map_session_data> sd, SP, int, int); +int pc_skill(dumb_ptr<map_session_data>, SkillID, int, int); -int pc_attack(struct map_session_data *, int, int); -int pc_stopattack(struct map_session_data *); +int pc_attack(dumb_ptr<map_session_data>, int, int); +int pc_stopattack(dumb_ptr<map_session_data>); -int pc_gainexp_reason(struct map_session_data *, int, int, +int pc_gainexp_reason(dumb_ptr<map_session_data>, int, int, PC_GAINEXP_REASON reason); -int pc_extract_healer_exp(struct map_session_data *, int max); // [Fate] Used by healers: extract healer-xp from the target, return result (up to max) - -int pc_nextbaseexp(struct map_session_data *); -int pc_nextjobexp(struct map_session_data *); -int pc_need_status_point(struct map_session_data *, SP); -int pc_statusup(struct map_session_data *, SP); -int pc_statusup2(struct map_session_data *, SP, int); -int pc_skillup(struct map_session_data *, SkillID); -int pc_resetlvl(struct map_session_data *, int type); -int pc_resetstate(struct map_session_data *); -int pc_resetskill(struct map_session_data *); -int pc_equipitem(struct map_session_data *, int, EPOS); -int pc_unequipitem(struct map_session_data *, int, CalcStatus); -int pc_unequipinvyitem(struct map_session_data *, int, CalcStatus); -int pc_useitem(struct map_session_data *, int); - -int pc_damage(struct block_list *, struct map_session_data *, int); -int pc_heal(struct map_session_data *, int, int); -int pc_itemheal(struct map_session_data *sd, int hp, int sp); -int pc_percentheal(struct map_session_data *sd, int, int); -int pc_setoption(struct map_session_data *, Option); -int pc_changelook(struct map_session_data *, LOOK, int); - -int pc_readparam(struct map_session_data *, SP); -int pc_setparam(struct map_session_data *, SP, int); -int pc_readreg(struct map_session_data *, int); -int pc_setreg(struct map_session_data *, int, int); -char *pc_readregstr(struct map_session_data *sd, int reg); -int pc_setregstr(struct map_session_data *sd, int reg, const char *str); -int pc_readglobalreg(struct map_session_data *, const char *); -int pc_setglobalreg(struct map_session_data *, const char *, int); -int pc_readaccountreg(struct map_session_data *, const char *); -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, interval_t tick, +int pc_extract_healer_exp(dumb_ptr<map_session_data>, int max); // [Fate] Used by healers: extract healer-xp from the target, return result (up to max) + +int pc_nextbaseexp(dumb_ptr<map_session_data>); +int pc_nextjobexp(dumb_ptr<map_session_data>); +int pc_need_status_point(dumb_ptr<map_session_data>, SP); +int pc_statusup(dumb_ptr<map_session_data>, SP); +int pc_statusup2(dumb_ptr<map_session_data>, SP, int); +int pc_skillup(dumb_ptr<map_session_data>, SkillID); +int pc_resetlvl(dumb_ptr<map_session_data>, int type); +int pc_resetstate(dumb_ptr<map_session_data>); +int pc_resetskill(dumb_ptr<map_session_data>); +int pc_equipitem(dumb_ptr<map_session_data>, int, EPOS); +int pc_unequipitem(dumb_ptr<map_session_data>, int, CalcStatus); +int pc_unequipinvyitem(dumb_ptr<map_session_data>, int, CalcStatus); +int pc_useitem(dumb_ptr<map_session_data>, int); + +int pc_damage(dumb_ptr<block_list>, dumb_ptr<map_session_data>, int); +int pc_heal(dumb_ptr<map_session_data>, int, int); +int pc_itemheal(dumb_ptr<map_session_data> sd, int hp, int sp); +int pc_percentheal(dumb_ptr<map_session_data> sd, int, int); +int pc_setoption(dumb_ptr<map_session_data>, Option); +int pc_changelook(dumb_ptr<map_session_data>, LOOK, int); + +int pc_readparam(dumb_ptr<map_session_data>, SP); +int pc_setparam(dumb_ptr<map_session_data>, SP, int); +int pc_readreg(dumb_ptr<map_session_data>, int); +int pc_setreg(dumb_ptr<map_session_data>, int, int); +char *pc_readregstr(dumb_ptr<map_session_data> sd, int reg); +int pc_setregstr(dumb_ptr<map_session_data> sd, int reg, const char *str); +int pc_readglobalreg(dumb_ptr<map_session_data>, const char *); +int pc_setglobalreg(dumb_ptr<map_session_data>, const char *, int); +int pc_readaccountreg(dumb_ptr<map_session_data>, const char *); +int pc_setaccountreg(dumb_ptr<map_session_data>, const char *, int); +int pc_readaccountreg2(dumb_ptr<map_session_data>, const char *); +int pc_setaccountreg2(dumb_ptr<map_session_data>, const char *, int); + +int pc_addeventtimer(dumb_ptr<map_session_data> sd, interval_t tick, const char *name); -int pc_cleareventtimer(struct map_session_data *sd); +int pc_cleareventtimer(dumb_ptr<map_session_data> sd); -int pc_calc_pvprank(struct map_session_data *sd); +int pc_calc_pvprank(dumb_ptr<map_session_data> sd); void pc_calc_pvprank_timer(TimerData *, tick_t, int); -int pc_marriage(struct map_session_data *sd, - struct map_session_data *dstsd); -int pc_divorce(struct map_session_data *sd); -struct map_session_data *pc_get_partner(struct map_session_data *sd); +int pc_marriage(dumb_ptr<map_session_data> sd, + dumb_ptr<map_session_data> dstsd); +int pc_divorce(dumb_ptr<map_session_data> sd); +dumb_ptr<map_session_data> pc_get_partner(dumb_ptr<map_session_data> sd); int pc_set_gm_level(int account_id, int level); -void pc_setstand(struct map_session_data *sd); -void pc_cleanup(struct map_session_data *sd); // [Fate] Clean up after a logged-out PC +void pc_setstand(dumb_ptr<map_session_data> sd); +void pc_cleanup(dumb_ptr<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, interval_t); -int pc_delinvincibletimer(struct map_session_data *sd); -int pc_logout(struct map_session_data *sd); // [fate] Player logs out +int pc_setinvincibletimer(dumb_ptr<map_session_data> sd, interval_t); +int pc_delinvincibletimer(dumb_ptr<map_session_data> sd); +int pc_logout(dumb_ptr<map_session_data> sd); // [fate] Player logs out int do_init_pc(void); diff --git a/src/map/script.cpp b/src/map/script.cpp index dfb6dbe..6d65fd2 100644 --- a/src/map/script.cpp +++ b/src/map/script.cpp @@ -995,9 +995,9 @@ enum *------------------------------------------ */ static -struct map_session_data *script_rid2sd(ScriptState *st) +dumb_ptr<map_session_data> script_rid2sd(ScriptState *st) { - struct map_session_data *sd = map_id2sd(st->rid); + dumb_ptr<map_session_data> sd = map_id2sd(st->rid); if (!sd) { PRINTF("script_rid2sd: fatal error ! player not attached!\n"); @@ -1012,7 +1012,7 @@ struct map_session_data *script_rid2sd(ScriptState *st) static void get_val(ScriptState *st, struct script_data *data) { - struct map_session_data *sd = NULL; + dumb_ptr<map_session_data> sd = NULL; if (data->type == ScriptCode::NAME) { char *name = str_buf + str_data[data->u.num & 0x00ffffff].str; @@ -1112,7 +1112,7 @@ struct script_data get_val2(ScriptState *st, int num) *------------------------------------------ */ static -void set_reg(struct map_session_data *sd, int num, const char *name, struct script_data vd) +void set_reg(dumb_ptr<map_session_data> sd, int num, const char *name, struct script_data vd) { char prefix = *name; char postfix = name[strlen(name) - 1]; @@ -1164,7 +1164,7 @@ void set_reg(struct map_session_data *sd, int num, const char *name, struct scri } static -void set_reg(struct map_session_data *sd, int num, const char *name, int id) +void set_reg(dumb_ptr<map_session_data> sd, int num, const char *name, int id) { struct script_data vd; vd.u.num = id; @@ -1172,7 +1172,7 @@ void set_reg(struct map_session_data *sd, int num, const char *name, int id) } static -void set_reg(struct map_session_data *sd, int num, const char *name, const char *zd) +void set_reg(dumb_ptr<map_session_data> sd, int num, const char *name, const char *zd) { struct script_data vd; vd.u.str = zd; @@ -1501,7 +1501,7 @@ void builtin_menu(ScriptState *st) int menu_choices = 0; int finished_menu_items = 0; // [fate] set to 1 after we hit the first empty string - struct map_session_data *sd; + dumb_ptr<map_session_data> sd; sd = script_rid2sd(st); @@ -1609,7 +1609,7 @@ static void builtin_isat(ScriptState *st) { int x, y; - struct map_session_data *sd = script_rid2sd(st); + dumb_ptr<map_session_data> sd = script_rid2sd(st); const char *str = conv_str(st, &(st->stack->stack_data[st->start + 2])); x = conv_num(st, &(st->stack->stack_data[st->start + 3])); @@ -1632,7 +1632,7 @@ static void builtin_warp(ScriptState *st) { int x, y; - struct map_session_data *sd = script_rid2sd(st); + dumb_ptr<map_session_data> sd = script_rid2sd(st); const char *str = conv_str(st, &(st->stack->stack_data[st->start + 2])); x = conv_num(st, &(st->stack->stack_data[st->start + 3])); @@ -1664,12 +1664,13 @@ void builtin_warp(ScriptState *st) *------------------------------------------ */ static -void builtin_areawarp_sub(struct block_list *bl, const char *mapname, int x, int y) +void builtin_areawarp_sub(dumb_ptr<block_list> bl, const char *mapname, int x, int y) { + dumb_ptr<map_session_data> sd = bl->as_player(); if (strcmp(mapname, "Random") == 0) - pc_randomwarp((struct map_session_data *) bl, BeingRemoveWhy::WARPED); + pc_randomwarp(sd, BeingRemoveWhy::WARPED); else - pc_setpos((struct map_session_data *) bl, mapname, x, y, BeingRemoveWhy::GONE); + pc_setpos(sd, mapname, x, y, BeingRemoveWhy::GONE); } static @@ -1743,7 +1744,7 @@ void builtin_percentheal(ScriptState *st) static void builtin_input(ScriptState *st) { - struct map_session_data *sd = NULL; + dumb_ptr<map_session_data> sd = NULL; int num = (st->end > st->start + 2) ? st->stack->stack_data[st->start + 2].u.num : 0; @@ -1836,7 +1837,7 @@ void builtin_if (ScriptState *st) static void builtin_set(ScriptState *st) { - struct map_session_data *sd = NULL; + dumb_ptr<map_session_data> sd = NULL; int num = st->stack->stack_data[st->start + 2].u.num; char *name = str_buf + str_data[num & 0x00ffffff].str; char prefix = *name; @@ -1873,7 +1874,7 @@ void builtin_set(ScriptState *st) static void builtin_setarray(ScriptState *st) { - struct map_session_data *sd = NULL; + dumb_ptr<map_session_data> sd = NULL; int num = st->stack->stack_data[st->start + 2].u.num; char *name = str_buf + str_data[num & 0x00ffffff].str; char prefix = *name; @@ -1904,7 +1905,7 @@ void builtin_setarray(ScriptState *st) static void builtin_cleararray(ScriptState *st) { - struct map_session_data *sd = NULL; + dumb_ptr<map_session_data> sd = NULL; int num = st->stack->stack_data[st->start + 2].u.num; char *name = str_buf + str_data[num & 0x00ffffff].str; char prefix = *name; @@ -2014,7 +2015,7 @@ static void builtin_countitem(ScriptState *st) { int nameid = 0, count = 0, i; - struct map_session_data *sd; + dumb_ptr<map_session_data> sd; struct script_data *data; @@ -2055,7 +2056,7 @@ static void builtin_checkweight(ScriptState *st) { int nameid = 0, amount; - struct map_session_data *sd; + dumb_ptr<map_session_data> sd; struct script_data *data; sd = script_rid2sd(st); @@ -2100,7 +2101,7 @@ void builtin_getitem(ScriptState *st) { int nameid, amount; struct item item_tmp; - struct map_session_data *sd; + dumb_ptr<map_session_data> sd; struct script_data *data; sd = script_rid2sd(st); @@ -2155,7 +2156,7 @@ void builtin_makeitem(ScriptState *st) int nameid, amount, flag = 0; int x, y, m; struct item item_tmp; - struct map_session_data *sd; + dumb_ptr<map_session_data> sd; struct script_data *data; sd = script_rid2sd(st); @@ -2205,7 +2206,7 @@ static void builtin_delitem(ScriptState *st) { int nameid = 0, amount, i; - struct map_session_data *sd; + dumb_ptr<map_session_data> sd; struct script_data *data; sd = script_rid2sd(st); @@ -2269,7 +2270,7 @@ void builtin_delitem(ScriptState *st) static void builtin_readparam(ScriptState *st) { - struct map_session_data *sd; + dumb_ptr<map_session_data> sd; SP type = SP(conv_num(st, &(st->stack->stack_data[st->start + 2]))); if (st->end > st->start + 3) @@ -2295,7 +2296,7 @@ static void builtin_getcharid(ScriptState *st) { int num; - struct map_session_data *sd; + dumb_ptr<map_session_data> sd; num = conv_num(st, &(st->stack->stack_data[st->start + 2])); if (st->end > st->start + 3) @@ -2347,7 +2348,7 @@ char *builtin_getpartyname_sub(int party_id) static void builtin_strcharinfo(ScriptState *st) { - struct map_session_data *sd; + dumb_ptr<map_session_data> sd; int num; sd = script_rid2sd(st); @@ -2401,7 +2402,7 @@ static void builtin_getequipid(ScriptState *st) { int i, num; - struct map_session_data *sd; + dumb_ptr<map_session_data> sd; struct item_data *item; sd = script_rid2sd(st); @@ -2434,7 +2435,7 @@ static void builtin_getequipname(ScriptState *st) { int i, num; - struct map_session_data *sd; + dumb_ptr<map_session_data> sd; struct item_data *item; char *buf; @@ -2467,7 +2468,7 @@ void builtin_statusup2(ScriptState *st) { SP type = SP(conv_num(st, &(st->stack->stack_data[st->start + 2]))); int val = conv_num(st, &(st->stack->stack_data[st->start + 3])); - struct map_session_data *sd = script_rid2sd(st); + dumb_ptr<map_session_data> sd = script_rid2sd(st); pc_statusup2(sd, type, val); } @@ -2481,7 +2482,7 @@ void builtin_bonus(ScriptState *st) { SP type = SP(conv_num(st, &(st->stack->stack_data[st->start + 2]))); int val = conv_num(st, &(st->stack->stack_data[st->start + 3])); - struct map_session_data *sd = script_rid2sd(st); + dumb_ptr<map_session_data> sd = script_rid2sd(st); pc_bonus(sd, type, val); } @@ -2496,7 +2497,7 @@ void builtin_bonus2(ScriptState *st) SP type = SP(conv_num(st, &(st->stack->stack_data[st->start + 2]))); int type2 = conv_num(st, &(st->stack->stack_data[st->start + 3])); int val = conv_num(st, &(st->stack->stack_data[st->start + 4])); - struct map_session_data *sd = script_rid2sd(st); + dumb_ptr<map_session_data> sd = script_rid2sd(st); pc_bonus2(sd, type, type2, val); } @@ -2509,7 +2510,7 @@ static void builtin_skill(ScriptState *st) { int level, flag = 1; - struct map_session_data *sd; + dumb_ptr<map_session_data> sd; SkillID id = SkillID(conv_num(st, &(st->stack->stack_data[st->start + 2]))); level = conv_num(st, &(st->stack->stack_data[st->start + 3])); @@ -2529,7 +2530,7 @@ static void builtin_setskill(ScriptState *st) { int level; - struct map_session_data *sd; + dumb_ptr<map_session_data> sd; SkillID id = static_cast<SkillID>(conv_num(st, &(st->stack->stack_data[st->start + 2]))); level = conv_num(st, &(st->stack->stack_data[st->start + 3])); @@ -2578,7 +2579,7 @@ void builtin_end(ScriptState *st) static void builtin_getopt2(ScriptState *st) { - struct map_session_data *sd; + dumb_ptr<map_session_data> sd; sd = script_rid2sd(st); @@ -2594,7 +2595,7 @@ void builtin_getopt2(ScriptState *st) static void builtin_setopt2(ScriptState *st) { - struct map_session_data *sd; + dumb_ptr<map_session_data> sd; Opt2 new_opt2 = Opt2(conv_num(st, &(st->stack->stack_data[st->start + 2]))); sd = script_rid2sd(st); @@ -2729,7 +2730,7 @@ void builtin_openstorage(ScriptState *st) { // int sync = 0; // if (st->end >= 3) sync = conv_num(st,& (st->stack->stack_data[st->start+2])); - struct map_session_data *sd = script_rid2sd(st); + dumb_ptr<map_session_data> sd = script_rid2sd(st); // if (sync) { st->state = STOP; @@ -2746,7 +2747,7 @@ void builtin_openstorage(ScriptState *st) static void builtin_getexp(ScriptState *st) { - struct map_session_data *sd = script_rid2sd(st); + dumb_ptr<map_session_data> sd = script_rid2sd(st); int base = 0, job = 0; base = conv_num(st, &(st->stack->stack_data[st->start + 2])); @@ -2811,19 +2812,20 @@ void builtin_areamonster(ScriptState *st) *------------------------------------------ */ static -void builtin_killmonster_sub(struct block_list *bl, const char *event, int allflag) +void builtin_killmonster_sub(dumb_ptr<block_list> bl, const char *event, int allflag) { + dumb_ptr<mob_data> md = bl->as_mob(); if (!allflag) { - if (strcmp(event, ((struct mob_data *) bl)->npc_event) == 0) - mob_delete((struct mob_data *) bl); + if (strcmp(event, md->npc_event) == 0) + mob_delete(md); return; } else if (allflag) { - 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); + if (md->spawndelay1 == static_cast<interval_t>(-1) + && md->spawndelay2 == static_cast<interval_t>(-1)) + mob_delete(md); return; } } @@ -2844,9 +2846,9 @@ void builtin_killmonster(ScriptState *st) } static -void builtin_killmonsterall_sub(struct block_list *bl) +void builtin_killmonsterall_sub(dumb_ptr<block_list> bl) { - mob_delete((struct mob_data *) bl); + mob_delete(bl->as_mob()); } static @@ -2891,11 +2893,13 @@ void builtin_addtimer(ScriptState *st) static void builtin_initnpctimer(ScriptState *st) { - struct npc_data *nd; + dumb_ptr<npc_data> nd_; if (st->end > st->start + 2) - nd = npc_name2id(conv_str(st, &(st->stack->stack_data[st->start + 2]))); + nd_ = npc_name2id(conv_str(st, &(st->stack->stack_data[st->start + 2]))); else - nd = (struct npc_data *) map_id2bl(st->oid); + nd_ = map_id_as_npc(st->oid); + assert (nd_ && nd_->npc_subtype == NpcSubtype::SCRIPT); + dumb_ptr<npc_data_script> nd = nd_->as_script(); npc_settimerevent_tick(nd, interval_t::zero()); npc_timerevent_start(nd); @@ -2908,11 +2912,13 @@ void builtin_initnpctimer(ScriptState *st) static void builtin_startnpctimer(ScriptState *st) { - struct npc_data *nd; + dumb_ptr<npc_data> nd_; if (st->end > st->start + 2) - nd = npc_name2id(conv_str(st, &(st->stack->stack_data[st->start + 2]))); + nd_ = npc_name2id(conv_str(st, &(st->stack->stack_data[st->start + 2]))); else - nd = (struct npc_data *) map_id2bl(st->oid); + nd_ = map_id_as_npc(st->oid); + assert (nd_ && nd_->npc_subtype == NpcSubtype::SCRIPT); + dumb_ptr<npc_data_script> nd = nd_->as_script(); npc_timerevent_start(nd); } @@ -2924,11 +2930,13 @@ void builtin_startnpctimer(ScriptState *st) static void builtin_stopnpctimer(ScriptState *st) { - struct npc_data *nd; + dumb_ptr<npc_data> nd_; if (st->end > st->start + 2) - nd = npc_name2id(conv_str(st, &(st->stack->stack_data[st->start + 2]))); + nd_ = npc_name2id(conv_str(st, &(st->stack->stack_data[st->start + 2]))); else - nd = (struct npc_data *) map_id2bl(st->oid); + nd_ = map_id_as_npc(st->oid); + assert (nd_ && nd_->npc_subtype == NpcSubtype::SCRIPT); + dumb_ptr<npc_data_script> nd = nd_->as_script(); npc_timerevent_stop(nd); } @@ -2940,13 +2948,15 @@ void builtin_stopnpctimer(ScriptState *st) static void builtin_getnpctimer(ScriptState *st) { - struct npc_data *nd; + dumb_ptr<npc_data> nd_; int type = conv_num(st, &(st->stack->stack_data[st->start + 2])); int val = 0; if (st->end > st->start + 3) - nd = npc_name2id(conv_str(st, &(st->stack->stack_data[st->start + 3]))); + nd_ = npc_name2id(conv_str(st, &(st->stack->stack_data[st->start + 3]))); else - nd = (struct npc_data *) map_id2bl(st->oid); + nd_ = map_id_as_npc(st->oid); + assert (nd_ && nd_->npc_subtype == NpcSubtype::SCRIPT); + dumb_ptr<npc_data_script> nd = nd_->as_script(); switch (type) { @@ -2954,10 +2964,10 @@ void builtin_getnpctimer(ScriptState *st) val = (int) npc_gettimerevent_tick(nd).count(); break; case 1: - val = (nd->u.scr.nexttimer >= 0); + val = (nd->scr.nexttimer >= 0); break; case 2: - val = nd->u.scr.timeramount; + val = nd->scr.timeramount; break; } push_val(st->stack, ScriptCode::INT, val); @@ -2970,12 +2980,14 @@ void builtin_getnpctimer(ScriptState *st) static void builtin_setnpctimer(ScriptState *st) { - struct npc_data *nd; + dumb_ptr<npc_data> nd_; 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]))); + nd_ = npc_name2id(conv_str(st, &(st->stack->stack_data[st->start + 3]))); else - nd = (struct npc_data *) map_id2bl(st->oid); + nd_ = map_id_as_npc(st->oid); + assert (nd_ && nd_->npc_subtype == NpcSubtype::SCRIPT); + dumb_ptr<npc_data_script> nd = nd_->as_script(); npc_settimerevent_tick(nd, tick); } @@ -2993,8 +3005,8 @@ void builtin_announce(ScriptState *st) if (flag & 0x0f) { - struct block_list *bl = (flag & 0x08) ? map_id2bl(st->oid) : - (struct block_list *) script_rid2sd(st); + dumb_ptr<block_list> bl = (flag & 0x08) ? map_id2bl(st->oid) : + (dumb_ptr<block_list>) script_rid2sd(st); clif_GMmessage(bl, str, flag); } else @@ -3006,7 +3018,7 @@ void builtin_announce(ScriptState *st) *------------------------------------------ */ static -void builtin_mapannounce_sub(struct block_list *bl, const char *str, int flag) +void builtin_mapannounce_sub(dumb_ptr<block_list> bl, const char *str, int flag) { clif_GMmessage(bl, str, flag | 3); } @@ -3034,7 +3046,7 @@ static void builtin_getusers(ScriptState *st) { int flag = conv_num(st, &(st->stack->stack_data[st->start + 2])); - struct block_list *bl = map_id2bl((flag & 0x08) ? st->oid : st->rid); + dumb_ptr<block_list> bl = map_id2bl((flag & 0x08) ? st->oid : st->rid); int val = 0; switch (flag & 0x07) { @@ -3070,15 +3082,15 @@ void builtin_getmapusers(ScriptState *st) *------------------------------------------ */ static -void builtin_getareausers_sub(struct block_list *, int *users) +void builtin_getareausers_sub(dumb_ptr<block_list>, int *users) { (*users)++; } static -void builtin_getareausers_living_sub(struct block_list *bl, int *users) +void builtin_getareausers_living_sub(dumb_ptr<block_list> bl, int *users) { - if (!pc_isdead((struct map_session_data *)bl)) + if (!pc_isdead(bl->as_player())) (*users)++; } @@ -3112,9 +3124,9 @@ void builtin_getareausers(ScriptState *st) *------------------------------------------ */ static -void builtin_getareadropitem_sub(struct block_list *bl, int item, int *amount) +void builtin_getareadropitem_sub(dumb_ptr<block_list> bl, int item, int *amount) { - struct flooritem_data *drop = (struct flooritem_data *) bl; + dumb_ptr<flooritem_data> drop = bl->as_item(); if (drop->item_data.nameid == item) (*amount) += drop->item_data.amount; @@ -3122,11 +3134,12 @@ void builtin_getareadropitem_sub(struct block_list *bl, int item, int *amount) } static -void builtin_getareadropitem_sub_anddelete(struct block_list *bl, int item, int *amount) +void builtin_getareadropitem_sub_anddelete(dumb_ptr<block_list> bl, int item, int *amount) { - struct flooritem_data *drop = (struct flooritem_data *) bl; + dumb_ptr<flooritem_data> drop = bl->as_item(); - if (drop->item_data.nameid == item) { + if (drop->item_data.nameid == item) + { (*amount) += drop->item_data.amount; clif_clearflooritem(drop, 0); map_delobject(drop->bl_id, drop->bl_type); @@ -3205,7 +3218,7 @@ void builtin_disablenpc(ScriptState *st) static void builtin_sc_start(ScriptState *st) { - struct block_list *bl; + dumb_ptr<block_list> bl; 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]))); @@ -3233,7 +3246,7 @@ void builtin_sc_start(ScriptState *st) static void builtin_sc_end(ScriptState *st) { - struct block_list *bl; + dumb_ptr<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, nullptr); @@ -3242,7 +3255,7 @@ void builtin_sc_end(ScriptState *st) static void builtin_sc_check(ScriptState *st) { - struct block_list *bl; + dumb_ptr<block_list> bl; StatusChange type = StatusChange(conv_num(st, &(st->stack->stack_data[st->start + 2]))); bl = map_id2bl(st->rid); @@ -3269,7 +3282,7 @@ void builtin_debugmes(ScriptState *st) static void builtin_resetstatus(ScriptState *st) { - struct map_session_data *sd; + dumb_ptr<map_session_data> sd; sd = script_rid2sd(st); pc_resetstate(sd); } @@ -3281,7 +3294,7 @@ void builtin_resetstatus(ScriptState *st) static void builtin_changesex(ScriptState *st) { - struct map_session_data *sd = NULL; + dumb_ptr<map_session_data> sd = NULL; sd = script_rid2sd(st); if (sd->status.sex == 0) @@ -3658,9 +3671,9 @@ void builtin_cmdothernpc(ScriptState *st) // Added by RoVeRT } static -void builtin_mobcount_sub(struct block_list *bl, const char *event, int *c) +void builtin_mobcount_sub(dumb_ptr<block_list> bl, const char *event, int *c) { - if (strcmp(event, ((struct mob_data *) bl)->npc_event) == 0) + if (strcmp(event, bl->as_mob()->npc_event) == 0) (*c)++; } @@ -3687,8 +3700,8 @@ static void builtin_marriage(ScriptState *st) { const char *partner = conv_str(st, &(st->stack->stack_data[st->start + 2])); - struct map_session_data *sd = script_rid2sd(st); - struct map_session_data *p_sd = map_nick2sd(partner); + dumb_ptr<map_session_data> sd = script_rid2sd(st); + dumb_ptr<map_session_data> p_sd = map_nick2sd(partner); if (sd == NULL || p_sd == NULL || pc_marriage(sd, p_sd) < 0) { @@ -3701,7 +3714,7 @@ void builtin_marriage(ScriptState *st) static void builtin_divorce(ScriptState *st) { - struct map_session_data *sd = script_rid2sd(st); + dumb_ptr<map_session_data> sd = script_rid2sd(st); st->state = STOP; // rely on pc_divorce to restart @@ -3765,7 +3778,7 @@ void builtin_getspellinvocation(ScriptState *st) static void builtin_getpartnerid2(ScriptState *st) { - struct map_session_data *sd = script_rid2sd(st); + dumb_ptr<map_session_data> sd = script_rid2sd(st); push_val(st->stack, ScriptCode::INT, sd->status.partner_id); } @@ -3777,7 +3790,7 @@ void builtin_getpartnerid2(ScriptState *st) static void builtin_getinventorylist(ScriptState *st) { - struct map_session_data *sd = script_rid2sd(st); + dumb_ptr<map_session_data> sd = script_rid2sd(st); int i, j = 0; if (!sd) return; @@ -3815,7 +3828,7 @@ void builtin_getinventorylist(ScriptState *st) static void builtin_getactivatedpoolskilllist(ScriptState *st) { - struct map_session_data *sd = script_rid2sd(st); + dumb_ptr<map_session_data> sd = script_rid2sd(st); SkillID pool_skills[MAX_SKILL_POOL]; int skill_pool_size = skill_pool(sd, pool_skills); int i, count = 0; @@ -3847,7 +3860,7 @@ void builtin_getactivatedpoolskilllist(ScriptState *st) static void builtin_getunactivatedpoolskilllist(ScriptState *st) { - struct map_session_data *sd = script_rid2sd(st); + dumb_ptr<map_session_data> sd = script_rid2sd(st); int i, count = 0; if (!sd) @@ -3877,7 +3890,7 @@ void builtin_getunactivatedpoolskilllist(ScriptState *st) static void builtin_poolskill(ScriptState *st) { - struct map_session_data *sd = script_rid2sd(st); + dumb_ptr<map_session_data> sd = script_rid2sd(st); SkillID skill_id = SkillID(conv_num(st, &(st->stack->stack_data[st->start + 2]))); skill_pool_activate(sd, skill_id); @@ -3888,7 +3901,7 @@ void builtin_poolskill(ScriptState *st) static void builtin_unpoolskill(ScriptState *st) { - struct map_session_data *sd = script_rid2sd(st); + dumb_ptr<map_session_data> sd = script_rid2sd(st); SkillID skill_id = SkillID(conv_num(st, &(st->stack->stack_data[st->start + 2]))); skill_pool_deactivate(sd, skill_id); @@ -3913,7 +3926,7 @@ void builtin_misceffect(ScriptState *st) int type; int id = 0; const char *name = NULL; - struct block_list *bl = NULL; + dumb_ptr<block_list> bl = NULL; type = conv_num(st, &(st->stack->stack_data[st->start + 2])); @@ -3931,7 +3944,7 @@ void builtin_misceffect(ScriptState *st) if (name) { - struct map_session_data *sd = map_nick2sd(name); + dumb_ptr<map_session_data> sd = map_nick2sd(name); if (sd) bl = sd; } @@ -3941,7 +3954,7 @@ void builtin_misceffect(ScriptState *st) bl = map_id2bl(st->oid); else { - struct map_session_data *sd = script_rid2sd(st); + dumb_ptr<map_session_data> sd = script_rid2sd(st); if (sd) bl = sd; } @@ -3958,7 +3971,7 @@ void builtin_misceffect(ScriptState *st) static void builtin_specialeffect(ScriptState *st) { - struct block_list *bl = map_id2bl(st->oid); + dumb_ptr<block_list> bl = map_id2bl(st->oid); if (bl == NULL) return; @@ -3973,7 +3986,7 @@ void builtin_specialeffect(ScriptState *st) static void builtin_specialeffect2(ScriptState *st) { - struct map_session_data *sd = script_rid2sd(st); + dumb_ptr<map_session_data> sd = script_rid2sd(st); if (sd == NULL) return; @@ -3993,7 +4006,7 @@ void builtin_specialeffect2(ScriptState *st) static void builtin_nude(ScriptState *st) { - struct map_session_data *sd = script_rid2sd(st); + dumb_ptr<map_session_data> sd = script_rid2sd(st); if (sd == NULL) return; @@ -4013,7 +4026,7 @@ void builtin_nude(ScriptState *st) static void builtin_unequipbyid(ScriptState *st) { - struct map_session_data *sd = script_rid2sd(st); + dumb_ptr<map_session_data> sd = script_rid2sd(st); if (sd == NULL) return; @@ -4037,7 +4050,7 @@ void builtin_unequipbyid(ScriptState *st) static void builtin_gmcommand(ScriptState *st) { - struct map_session_data *sd; + dumb_ptr<map_session_data> sd; sd = script_rid2sd(st); const char *cmd = conv_str(st, &(st->stack->stack_data[st->start + 2])); @@ -4055,7 +4068,7 @@ static void builtin_npcwarp(ScriptState *st) { int x, y; - struct npc_data *nd = NULL; + dumb_ptr<npc_data> nd = NULL; x = conv_num(st, &(st->stack->stack_data[st->start + 2])); y = conv_num(st, &(st->stack->stack_data[st->start + 3])); @@ -4090,7 +4103,7 @@ void builtin_npcwarp(ScriptState *st) static void builtin_message(ScriptState *st) { - struct map_session_data *pl_sd = NULL; + dumb_ptr<map_session_data> pl_sd = NULL; const char *player = conv_str(st, &(st->stack->stack_data[st->start + 2])); const char *msg = conv_str(st, &(st->stack->stack_data[st->start + 3])); @@ -4112,7 +4125,7 @@ void builtin_npctalk(ScriptState *st) { char message[255]; - struct npc_data *nd = (struct npc_data *) map_id2bl(st->oid); + dumb_ptr<npc_data> nd = map_id_as_npc(st->oid); const char *str = conv_str(st, &(st->stack->stack_data[st->start + 2])); if (nd) @@ -4132,7 +4145,7 @@ void builtin_npctalk(ScriptState *st) static void builtin_getlook(ScriptState *st) { - struct map_session_data *sd = script_rid2sd(st); + dumb_ptr<map_session_data> sd = script_rid2sd(st); LOOK type = LOOK(conv_num(st, &(st->stack->stack_data[st->start + 2]))); int val = -1; @@ -4178,7 +4191,7 @@ void builtin_getsavepoint(ScriptState *st) { int x, y, type; char *mapname; - struct map_session_data *sd; + dumb_ptr<map_session_data> sd; sd = script_rid2sd(st); @@ -4207,9 +4220,9 @@ void builtin_getsavepoint(ScriptState *st) *------------------------------------------ */ static -void builtin_areatimer_sub(struct block_list *bl, interval_t tick, const char *event) +void builtin_areatimer_sub(dumb_ptr<block_list> bl, interval_t tick, const char *event) { - pc_addeventtimer((struct map_session_data *) bl, tick, event); + pc_addeventtimer(bl->as_player(), tick, event); } static @@ -4241,7 +4254,7 @@ static void builtin_isin(ScriptState *st) { int x1, y1, x2, y2; - struct map_session_data *sd = script_rid2sd(st); + dumb_ptr<map_session_data> sd = script_rid2sd(st); const char *str = conv_str(st, &(st->stack->stack_data[st->start + 2])); x1 = conv_num(st, &(st->stack->stack_data[st->start + 3])); @@ -4263,8 +4276,8 @@ void builtin_isin(ScriptState *st) static void builtin_shop(ScriptState *st) { - struct map_session_data *sd = script_rid2sd(st); - struct npc_data *nd; + dumb_ptr<map_session_data> sd = script_rid2sd(st); + dumb_ptr<npc_data> nd; if (!sd) return; @@ -4284,7 +4297,7 @@ void builtin_shop(ScriptState *st) static void builtin_isdead(ScriptState *st) { - struct map_session_data *sd = script_rid2sd(st); + dumb_ptr<map_session_data> sd = script_rid2sd(st); push_val(st->stack, ScriptCode::INT, pc_isdead(sd)); } @@ -4299,7 +4312,7 @@ void builtin_fakenpcname(ScriptState *st) const char *name = conv_str(st, &(st->stack->stack_data[st->start + 2])); const char *newname = conv_str(st, &(st->stack->stack_data[st->start + 3])); int newsprite = conv_num(st, &(st->stack->stack_data[st->start + 4])); - struct npc_data *nd = npc_name2id(name); + dumb_ptr<npc_data> nd = npc_name2id(name); if (!nd) return; strzcpy(nd->name, newname, sizeof(nd->name)); @@ -4318,7 +4331,7 @@ void builtin_fakenpcname(ScriptState *st) static void builtin_getx(ScriptState *st) { - struct map_session_data *sd = script_rid2sd(st); + dumb_ptr<map_session_data> sd = script_rid2sd(st); push_val(st->stack, ScriptCode::INT, sd->bl_x); } @@ -4330,7 +4343,7 @@ void builtin_getx(ScriptState *st) static void builtin_gety(ScriptState *st) { - struct map_session_data *sd = script_rid2sd(st); + dumb_ptr<map_session_data> sd = script_rid2sd(st); push_val(st->stack, ScriptCode::INT, sd->bl_y); } @@ -4341,7 +4354,7 @@ void builtin_gety(ScriptState *st) static void builtin_getmap(ScriptState *st) { - struct map_session_data *sd = script_rid2sd(st); + dumb_ptr<map_session_data> sd = script_rid2sd(st); // A map_data lives essentially forever. push_str(st->stack, ScriptCode::CONSTSTR, map[sd->bl_m].name); @@ -4832,7 +4845,7 @@ void run_script_main(const ScriptCode *script, int pos_, int, int, break; case END: { - struct map_session_data *sd = map_id2sd(st->rid); + dumb_ptr<map_session_data> sd = map_id2sd(st->rid); st->pos = -1; if (sd && sd->npc_id == st->oid) npc_event_dequeue(sd); @@ -4848,7 +4861,7 @@ void run_script_main(const ScriptCode *script, int pos_, int, int, if (st->state != END) { // 再開するためにスタック情報を保存 - struct map_session_data *sd = map_id2sd(st->rid); + dumb_ptr<map_session_data> sd = map_id2sd(st->rid); if (sd /* && sd->npc_stackbuf==NULL */ ) { if (sd->npc_stackbuf) @@ -4880,7 +4893,7 @@ int run_script_l(const ScriptCode *script, int pos_, int rid, int oid, { struct script_stack stack; ScriptState st; - struct map_session_data *sd = map_id2sd(rid); + dumb_ptr<map_session_data> sd = map_id2sd(rid); const ScriptCode *rootscript = script; int i; if (script == NULL || pos_ < 0) diff --git a/src/map/skill-pools.cpp b/src/map/skill-pools.cpp index ab0f856..99d9abf 100644 --- a/src/map/skill-pools.cpp +++ b/src/map/skill-pools.cpp @@ -22,7 +22,7 @@ void skill_pool_register(SkillID id) skill_pool_skills[skill_pool_skills_size++] = id; } -int skill_pool(struct map_session_data *sd, SkillID *skills) +int skill_pool(dumb_ptr<map_session_data> sd, SkillID *skills) { int i, count = 0; @@ -40,17 +40,17 @@ int skill_pool(struct map_session_data *sd, SkillID *skills) return count; } -int skill_pool_size(struct map_session_data *sd) +int skill_pool_size(dumb_ptr<map_session_data> sd) { return skill_pool(sd, NULL); } -int skill_pool_max(struct map_session_data *sd) +int skill_pool_max(dumb_ptr<map_session_data> sd) { return sd->status.skill[SkillID::TMW_SKILLPOOL].lv; } -int skill_pool_activate(struct map_session_data *sd, SkillID skill_id) +int skill_pool_activate(dumb_ptr<map_session_data> sd, SkillID skill_id) { if (bool(sd->status.skill[skill_id].flags & SkillFlags::POOL_ACTIVATED)) return 0; // Already there @@ -68,12 +68,12 @@ int skill_pool_activate(struct map_session_data *sd, SkillID skill_id) return 1; // failed } -bool skill_pool_is_activated(struct map_session_data *sd, SkillID skill_id) +bool skill_pool_is_activated(dumb_ptr<map_session_data> sd, SkillID skill_id) { return bool(sd->status.skill[skill_id].flags & SkillFlags::POOL_ACTIVATED); } -int skill_pool_deactivate(struct map_session_data *sd, SkillID skill_id) +int skill_pool_deactivate(dumb_ptr<map_session_data> sd, SkillID skill_id) { if (bool(sd->status.skill[skill_id].flags & SkillFlags::POOL_ACTIVATED)) { @@ -94,7 +94,7 @@ SP skill_stat(SkillID skill_id) return skill_db[skill_id].stat; } -int skill_power(struct map_session_data *sd, SkillID skill_id) +int skill_power(dumb_ptr<map_session_data> sd, SkillID skill_id) { SP stat = skill_stat(skill_id); int stat_value, skill_value; @@ -116,10 +116,10 @@ int skill_power(struct map_session_data *sd, SkillID skill_id) return result; } -int skill_power_bl(struct block_list *bl, SkillID skill) +int skill_power_bl(dumb_ptr<block_list> bl, SkillID skill) { if (bl->bl_type == BL::PC) - return skill_power((struct map_session_data *) bl, skill); + return skill_power(bl->as_player(), skill); else return 0; } diff --git a/src/map/skill.cpp b/src/map/skill.cpp index 66f1e4c..4f71f06 100644 --- a/src/map/skill.cpp +++ b/src/map/skill.cpp @@ -56,12 +56,12 @@ 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, +int skill_attack(BF attack_type, dumb_ptr<block_list> src, + dumb_ptr<block_list> dsrc, dumb_ptr<block_list> bl, 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); +void skill_devotion_end(dumb_ptr<map_session_data> md, + dumb_ptr<map_session_data> sd, int target); static void skill_status_change_timer(TimerData *tid, tick_t tick, int id, StatusChange type); @@ -146,11 +146,11 @@ int distance(int x0, int y0, int x1, int y1) * スキル追加効果 *------------------------------------------ */ -int skill_additional_effect(struct block_list *src, struct block_list *bl, +int skill_additional_effect(dumb_ptr<block_list> src, dumb_ptr<block_list> bl, SkillID skillid, int skilllv) { - struct map_session_data *sd = NULL; - struct mob_data *md = NULL; + dumb_ptr<map_session_data> sd = NULL; + dumb_ptr<mob_data> md = NULL; int luk; @@ -165,13 +165,11 @@ int skill_additional_effect(struct block_list *src, struct block_list *bl, if (src->bl_type == BL::PC) { - sd = (struct map_session_data *) src; - nullpo_ret(sd); + sd = src->as_player(); } else if (src->bl_type == BL::MOB) { - md = (struct mob_data *) src; - nullpo_ret(md); //未使用? + md = src->as_mob(); } sc_def_phys_shield_spell = 0; @@ -230,8 +228,8 @@ 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, +int skill_attack(BF attack_type, dumb_ptr<block_list> src, + dumb_ptr<block_list> dsrc, dumb_ptr<block_list> bl, SkillID skillid, int skilllv, tick_t tick, BCT flag) { struct Damage dmg; @@ -249,11 +247,11 @@ int skill_attack(BF attack_type, struct block_list *src, return 0; if (src->bl_prev == NULL || dsrc->bl_prev == NULL || bl->bl_prev == NULL) //prevよくわからない※ return 0; - if (src->bl_type == BL::PC && pc_isdead((struct map_session_data *) src)) //術者?がPCですでに死んでいたら何もしない + if (src->bl_type == BL::PC && pc_isdead(src->as_player())) //術者?がPCですでに死んでいたら何もしない return 0; - if (dsrc->bl_type == BL::PC && pc_isdead((struct map_session_data *) dsrc)) //術者?がPCですでに死んでいたら何もしない + if (dsrc->bl_type == BL::PC && pc_isdead(dsrc->as_player())) //術者?がPCですでに死んでいたら何もしない return 0; - if (bl->bl_type == BL::PC && pc_isdead((struct map_session_data *) bl)) //対象がPCですでに死んでいたら何もしない + if (bl->bl_type == BL::PC && pc_isdead(bl->as_player())) //対象がPCですでに死んでいたら何もしない return 0; //何もしない判定ここまで @@ -288,16 +286,14 @@ int skill_attack(BF attack_type, struct block_list *src, /* ダメージがあるなら追加効果判定 */ if (bl->bl_prev != NULL) { - struct map_session_data *sd = (struct map_session_data *) bl; - nullpo_ret(sd); - if (bl->bl_type != BL::PC || (sd && !pc_isdead(sd))) + dumb_ptr<map_session_data> sd = bl->as_player(); + if (bl->bl_type != BL::PC || !pc_isdead(sd)) { if (damage > 0) skill_additional_effect(src, bl, skillid, skilllv); if (bl->bl_type == BL::MOB && src != bl) /* スキル使用条件のMOBスキル */ { - struct mob_data *md = (struct mob_data *) bl; - nullpo_ret(md); + dumb_ptr<mob_data> md = bl->as_mob(); if (battle_config.mob_changetarget_byskill == 1) { int target; @@ -319,9 +315,8 @@ int skill_attack(BF attack_type, struct block_list *src, && src == dsrc && damage > 0) { - struct map_session_data *sd = (struct map_session_data *) src; + dumb_ptr<map_session_data> sd = src->as_player(); int hp = 0, sp = 0; - nullpo_ret(sd); if (sd->hp_drain_rate && dmg.damage > 0 && random_::chance({sd->hp_drain_rate, 100})) { @@ -349,13 +344,13 @@ int skill_attack(BF attack_type, struct block_list *src, return (dmg.damage + dmg.damage2); /* 与ダメを返す */ } -typedef int(*SkillFunc)(struct block_list *, struct block_list *, +typedef int(*SkillFunc)(dumb_ptr<block_list>, dumb_ptr<block_list>, SkillID, int, tick_t, BCT); static -void skill_area_sub(struct block_list *bl, - struct block_list *src, SkillID skill_id, int skill_lv, +void skill_area_sub(dumb_ptr<block_list> bl, + dumb_ptr<block_list> src, SkillID skill_id, int skill_lv, tick_t tick, BCT flag, SkillFunc func) { nullpo_retv(bl); @@ -382,23 +377,23 @@ static int skill_area_temp_id, skill_area_temp_hp; * (スパゲッティに向けて1歩前進!(ダメポ)) *------------------------------------------ */ -int skill_castend_damage_id(struct block_list *src, struct block_list *bl, +int skill_castend_damage_id(dumb_ptr<block_list> src, dumb_ptr<block_list> bl, SkillID skillid, int skilllv, tick_t tick, BCT flag) { - struct map_session_data *sd = NULL; + dumb_ptr<map_session_data> sd = NULL; nullpo_retr(1, src); nullpo_retr(1, bl); if (src->bl_type == BL::PC) - sd = (struct map_session_data *) src; + sd = src->as_player(); if (sd && pc_isdead(sd)) return 1; if (bl->bl_prev == NULL) return 1; - if (bl->bl_type == BL::PC && pc_isdead((struct map_session_data *) bl)) + if (bl->bl_type == BL::PC && pc_isdead(bl->as_player())) return 1; MapBlockLock lock; @@ -415,8 +410,7 @@ int skill_castend_damage_id(struct block_list *src, struct block_list *bl, /* 個別にダメージを与える */ if (src->bl_type == BL::MOB) { - struct mob_data *mb = (struct mob_data *) src; - nullpo_retr(1, mb); + dumb_ptr<mob_data> mb = src->as_mob(); mb->hp = skill_area_temp_hp; if (bl->bl_id != skill_area_temp_id) skill_attack(BF::MISC, src, src, bl, @@ -427,8 +421,7 @@ int skill_castend_damage_id(struct block_list *src, struct block_list *bl, } else { - struct mob_data *md; - if ((md = (struct mob_data *) src)) + dumb_ptr<mob_data> md = src->as_mob(); { skill_area_temp_id = bl->bl_id; skill_area_temp_hp = battle_get_hp(src); @@ -476,22 +469,22 @@ 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, +int skill_castend_nodamage_id(dumb_ptr<block_list> src, dumb_ptr<block_list> bl, SkillID skillid, int skilllv) { - struct map_session_data *sd = NULL; - struct map_session_data *dstsd = NULL; - struct mob_data *md = NULL; - struct mob_data *dstmd = NULL; + dumb_ptr<map_session_data> sd = NULL; + dumb_ptr<map_session_data> dstsd = NULL; + dumb_ptr<mob_data> md = NULL; + dumb_ptr<mob_data> dstmd = NULL; int sc_def_vit, sc_def_mdef, strip_fix; nullpo_retr(1, src); nullpo_retr(1, bl); if (src->bl_type == BL::PC) - sd = (struct map_session_data *) src; + sd = src->as_player(); else if (src->bl_type == BL::MOB) - md = (struct mob_data *) src; + md = src->as_mob(); sc_def_vit = 100 - (3 + battle_get_vit(bl) + battle_get_luk(bl) / 3); sc_def_vit = 100 - (3 + battle_get_vit(bl) + battle_get_luk(bl) / 3); @@ -500,13 +493,11 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, if (bl->bl_type == BL::PC) { - dstsd = (struct map_session_data *) bl; - nullpo_retr(1, dstsd); + dstsd = bl->as_player(); } else if (bl->bl_type == BL::MOB) { - dstmd = (struct mob_data *) bl; - nullpo_retr(1, dstmd); + dstmd = bl->as_mob(); if (sc_def_vit > 50) sc_def_vit = 50; if (sc_def_mdef > 50) @@ -553,9 +544,9 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, * 詠唱時間計算 *------------------------------------------ */ -interval_t skill_castfix(struct block_list *bl, interval_t interval) +interval_t skill_castfix(dumb_ptr<block_list> bl, interval_t interval) { - struct mob_data *md; // [Valaris] + dumb_ptr<mob_data> md; // [Valaris] eptr<struct status_change, StatusChange> sc_data; int dex; int castrate = 100; @@ -566,7 +557,7 @@ interval_t skill_castfix(struct block_list *bl, interval_t interval) if (bl->bl_type == BL::MOB) { // Crash fix [Valaris] - md = (struct mob_data *) bl; + md = bl->as_mob(); skill = md->skillid; lv = md->skilllv; } @@ -605,7 +596,7 @@ interval_t skill_castfix(struct block_list *bl, interval_t interval) * ディレイ計算 *------------------------------------------ */ -interval_t skill_delayfix(struct block_list *bl, interval_t interval) +interval_t skill_delayfix(dumb_ptr<block_list> bl, interval_t interval) { eptr<struct status_change, StatusChange> sc_data; @@ -632,13 +623,13 @@ interval_t skill_delayfix(struct block_list *bl, interval_t interval) * スキル詠唱キャンセル *------------------------------------------ */ -int skill_castcancel(struct block_list *bl, int) +int skill_castcancel(dumb_ptr<block_list> bl, int) { nullpo_ret(bl); if (bl->bl_type == BL::PC) { - struct map_session_data *sd = (struct map_session_data *) bl; + dumb_ptr<map_session_data> sd = bl->as_player(); tick_t tick = gettick(); sd->canact_tick = tick; sd->canmove_tick = tick; @@ -647,7 +638,7 @@ int skill_castcancel(struct block_list *bl, int) } else if (bl->bl_type == BL::MOB) { - struct mob_data *md = (struct mob_data *) bl; + dumb_ptr<mob_data> md = bl->as_mob(); if (md->skilltimer) { md->skilltimer.cancel(); @@ -662,7 +653,7 @@ int skill_castcancel(struct block_list *bl, int) * ディボーション 有効確認 *------------------------------------------ */ -void skill_devotion(struct map_session_data *md, int) +void skill_devotion(dumb_ptr<map_session_data> md, int) { // 総確認 int n; @@ -673,7 +664,7 @@ void skill_devotion(struct map_session_data *md, int) { if (md->dev.val1[n]) { - struct map_session_data *sd = map_id2sd(md->dev.val1[n]); + dumb_ptr<map_session_data> sd = map_id2sd(md->dev.val1[n]); // 相手が見つからない // 相手をディボしてるのが自分じゃない // 距離が離れてる if (sd == NULL || (md->bl_id != 0/* was something else - TODO remove this */) @@ -685,17 +676,18 @@ void skill_devotion(struct map_session_data *md, int) } } -int skill_devotion3(struct block_list *bl, int target) +int skill_devotion3(dumb_ptr<block_list> bl, int target) { // クルセが歩いた時の距離チェック - struct map_session_data *md; - struct map_session_data *sd; + dumb_ptr<map_session_data> md; + dumb_ptr<map_session_data> sd; int n, r = 0; nullpo_retr(1, bl); - if ((md = (struct map_session_data *) bl) == NULL - || (sd = map_id2sd(target)) == NULL) + md = bl->as_player(); + sd = map_id2sd(target); + if (sd == NULL) return 1; else r = distance(bl->bl_x, bl->bl_y, sd->bl_x, sd->bl_y); @@ -710,8 +702,8 @@ int skill_devotion3(struct block_list *bl, int target) return 0; } -void skill_devotion_end(struct map_session_data *md, - struct map_session_data *, int target) +void skill_devotion_end(dumb_ptr<map_session_data> md, + dumb_ptr<map_session_data>, int target) { // クルセと被ディボキャラのリセット nullpo_retv(md); @@ -719,7 +711,7 @@ void skill_devotion_end(struct map_session_data *md, md->dev.val1[target] = md->dev.val2[target] = 0; } -int skill_gangsterparadise(struct map_session_data *, int) +int skill_gangsterparadise(dumb_ptr<map_session_data>, int) { return 0; } @@ -733,7 +725,7 @@ int skill_gangsterparadise(struct map_session_data *, int) * ステータス異常終了 *------------------------------------------ */ -int skill_status_change_active(struct block_list *bl, StatusChange type) +int skill_status_change_active(dumb_ptr<block_list> bl, StatusChange type) { eptr<struct status_change, StatusChange> sc_data; @@ -752,7 +744,7 @@ int skill_status_change_active(struct block_list *bl, StatusChange type) return bool(sc_data[type].timer); } -void skill_status_change_end(struct block_list *bl, StatusChange type, TimerData *tid) +void skill_status_change_end(dumb_ptr<block_list> bl, StatusChange type, TimerData *tid) { eptr<struct status_change, StatusChange> sc_data; int opt_flag = 0, calc_flag = 0; @@ -848,10 +840,10 @@ void skill_status_change_end(struct block_list *bl, StatusChange type, TimerData clif_changeoption(bl); if (bl->bl_type == BL::PC && calc_flag) - pc_calcstatus((struct map_session_data *) bl, 0); /* ステータス再計算 */ + pc_calcstatus(bl->as_player(), 0); /* ステータス再計算 */ } -int skill_update_heal_animation(struct map_session_data *sd) +int skill_update_heal_animation(dumb_ptr<map_session_data> sd) { const Opt2 mask = Opt2::_heal; @@ -876,8 +868,8 @@ int skill_update_heal_animation(struct map_session_data *sd) */ void skill_status_change_timer(TimerData *tid, tick_t tick, int id, StatusChange type) { - struct block_list *bl; - struct map_session_data *sd = NULL; + dumb_ptr<block_list> bl; + dumb_ptr<map_session_data> sd = NULL; eptr<struct status_change, StatusChange> sc_data; //short *sc_count; //使ってない? @@ -889,7 +881,7 @@ void skill_status_change_timer(TimerData *tid, tick_t tick, int id, StatusChange return; if (bl->bl_type == BL::PC) - sd = (struct map_session_data *) bl; + sd = bl->as_player(); //sc_count=battle_get_sc_count(bl); //使ってない? @@ -919,13 +911,11 @@ void skill_status_change_timer(TimerData *tid, tick_t tick, int id, StatusChange if (bl->bl_type == BL::PC) { hp = 3 + hp * 3 / 200; - pc_heal((struct map_session_data *) bl, -hp, 0); + pc_heal(bl->as_player(), -hp, 0); } else if (bl->bl_type == BL::MOB) { - struct mob_data *md; - if ((md = ((struct mob_data *) bl)) == NULL) - break; + dumb_ptr<mob_data> md = bl->as_mob(); hp = 3 + hp / 200; md->hp -= hp; } @@ -970,18 +960,18 @@ void skill_status_change_timer(TimerData *tid, tick_t tick, int id, StatusChange * ステータス異常開始 *------------------------------------------ */ -int skill_status_change_start(struct block_list *bl, StatusChange type, +int skill_status_change_start(dumb_ptr<block_list> bl, StatusChange type, int val1, interval_t tick) { return skill_status_effect(bl, type, val1, tick, 0); } -int skill_status_effect(struct block_list *bl, StatusChange type, +int skill_status_effect(dumb_ptr<block_list> bl, StatusChange type, int val1, interval_t tick, int spell_invocation) { - struct map_session_data *sd = NULL; + dumb_ptr<map_session_data> sd = NULL; eptr<struct status_change, StatusChange> sc_data; short *sc_count; Option *option; @@ -1017,7 +1007,7 @@ int skill_status_effect(struct block_list *bl, StatusChange type, return 0; if (bl->bl_type == BL::PC) { - sd = (struct map_session_data *) bl; + sd = bl->as_player(); } else if (bl->bl_type == BL::MOB) { @@ -1156,7 +1146,7 @@ int skill_status_effect(struct block_list *bl, StatusChange type, * ステータス異常全解除 *------------------------------------------ */ -int skill_status_change_clear(struct block_list *bl, int type) +int skill_status_change_clear(dumb_ptr<block_list> bl, int type) { eptr<struct status_change, StatusChange> sc_data; short *sc_count; @@ -1211,13 +1201,13 @@ int skill_status_change_clear(struct block_list *bl, int type) * *------------------------------------------ */ -void skill_stop_dancing(struct block_list *, int) +void skill_stop_dancing(dumb_ptr<block_list>, int) { // TODO remove this } -void skill_unit_timer_sub_ondelete(struct block_list *bl, - struct block_list *src, unsigned int tick); +void skill_unit_timer_sub_ondelete(dumb_ptr<block_list> bl, + dumb_ptr<block_list> src, unsigned int tick); /*---------------------------------------------------------------------------- * アイテム合成 diff --git a/src/map/skill.hpp b/src/map/skill.hpp index a724781..ec354e2 100644 --- a/src/map/skill.hpp +++ b/src/map/skill.hpp @@ -63,40 +63,40 @@ int skill_get_inf2(SkillID id); int skill_get_maxcount(SkillID id); // 追加効果 -int skill_additional_effect(struct block_list *src, struct block_list *bl, +int skill_additional_effect(dumb_ptr<block_list> src, dumb_ptr<block_list> bl, SkillID skillid, int skilllv); -interval_t skill_castfix(struct block_list *bl, interval_t time); -interval_t skill_delayfix(struct block_list *bl, interval_t time); +interval_t skill_castfix(dumb_ptr<block_list> bl, interval_t time); +interval_t skill_delayfix(dumb_ptr<block_list> bl, interval_t time); -void skill_stop_dancing(struct block_list *src, int flag); +void skill_stop_dancing(dumb_ptr<block_list> src, int flag); // 詠唱キャンセル -int skill_castcancel(struct block_list *bl, int type); +int skill_castcancel(dumb_ptr<block_list> bl, int type); -int skill_gangsterparadise(struct map_session_data *sd, int type); -void skill_devotion(struct map_session_data *md, int target); -int skill_devotion3(struct block_list *bl, int target); +int skill_gangsterparadise(dumb_ptr<map_session_data> sd, int type); +void skill_devotion(dumb_ptr<map_session_data> md, int target); +int skill_devotion3(dumb_ptr<block_list> bl, int target); // ステータス異常 -int skill_status_effect(struct block_list *bl, StatusChange type, +int skill_status_effect(dumb_ptr<block_list> bl, StatusChange type, int val1, interval_t tick, int spell_invocation); -int skill_status_change_start(struct block_list *bl, StatusChange type, +int skill_status_change_start(dumb_ptr<block_list> bl, StatusChange type, int val1, interval_t tick); -int skill_status_change_active(struct block_list *bl, StatusChange type); // [fate] -void skill_status_change_end(struct block_list *bl, StatusChange type, TimerData *tid); -int skill_status_change_clear(struct block_list *bl, int type); +int skill_status_change_active(dumb_ptr<block_list> bl, StatusChange type); // [fate] +void skill_status_change_end(dumb_ptr<block_list> bl, StatusChange type, TimerData *tid); +int skill_status_change_clear(dumb_ptr<block_list> bl, int type); // mobスキルのため -int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl, +int skill_castend_nodamage_id(dumb_ptr<block_list> src, dumb_ptr<block_list> bl, SkillID skillid, int skilllv); -int skill_castend_damage_id(struct block_list *src, struct block_list *bl, +int skill_castend_damage_id(dumb_ptr<block_list> src, dumb_ptr<block_list> bl, 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 +int skill_update_heal_animation(dumb_ptr<map_session_data> sd); // [Fate] Check whether the healing flag must be updated, do so if needed void skill_reload(void); @@ -111,15 +111,15 @@ extern SkillID skill_pool_skills[MAX_POOL_SKILLS]; // All pool skills extern int skill_pool_skills_size; // Number of entries in skill_pool_skills // Yields all active skills in the skill pool; no more than MAX_SKILL_POOL. Return is number of skills. -int skill_pool(struct map_session_data *sd, SkillID *skills); -int skill_pool_size(struct map_session_data *sd); -int skill_pool_max(struct map_session_data *sd); // Max. number of pool skills +int skill_pool(dumb_ptr<map_session_data> sd, SkillID *skills); +int skill_pool_size(dumb_ptr<map_session_data> sd); +int skill_pool_max(dumb_ptr<map_session_data> sd); // Max. number of pool skills // Skill into skill pool. Return is zero iff okay. -int skill_pool_activate(struct map_session_data *sd, SkillID skill); +int skill_pool_activate(dumb_ptr<map_session_data> sd, SkillID skill); // Skill into skill pool. Return is zero when activated. -bool skill_pool_is_activated(struct map_session_data *sd, SkillID skill); +bool skill_pool_is_activated(dumb_ptr<map_session_data> sd, SkillID skill); // Skill out of skill pool. Return is zero iff okay. -int skill_pool_deactivate(struct map_session_data *sd, SkillID skill); +int skill_pool_deactivate(dumb_ptr<map_session_data> sd, SkillID skill); // Yield configurable skill name inline const char *skill_name(SkillID skill) @@ -130,8 +130,8 @@ const char *skill_name(SkillID skill) // This is zero if the skill is unknown // or if it's a pool skill that is outside of the skill pool, // otherwise a value from 0 to 255 (with 200 being the `normal maximum') -int skill_power(struct map_session_data *sd, SkillID skill); -int skill_power_bl(struct block_list *bl, SkillID skill); +int skill_power(dumb_ptr<map_session_data> sd, SkillID skill); +int skill_power_bl(dumb_ptr<block_list> bl, SkillID skill); // [Fate] Remember that a certain skill ID belongs to a pool skill void skill_pool_register(SkillID id); diff --git a/src/map/storage.cpp b/src/map/storage.cpp index dcd0dd7..463dd7c 100644 --- a/src/map/storage.cpp +++ b/src/map/storage.cpp @@ -84,7 +84,7 @@ void storage_delete(int account_id) * カプラ倉庫を開く *------------------------------------------ */ -int storage_storageopen(struct map_session_data *sd) +int storage_storageopen(dumb_ptr<map_session_data> sd) { nullpo_ret(sd); @@ -114,7 +114,7 @@ int storage_storageopen(struct map_session_data *sd) *------------------------------------------ */ static -int storage_additem(struct map_session_data *sd, struct storage *stor, +int storage_additem(dumb_ptr<map_session_data> sd, struct storage *stor, struct item *item_data, int amount) { struct item_data *data; @@ -160,7 +160,7 @@ int storage_additem(struct map_session_data *sd, struct storage *stor, *------------------------------------------ */ static -int storage_delitem(struct map_session_data *sd, struct storage *stor, +int storage_delitem(dumb_ptr<map_session_data> sd, struct storage *stor, int n, int amount) { @@ -184,7 +184,7 @@ int storage_delitem(struct map_session_data *sd, struct storage *stor, * Add an item to the storage from the inventory. *------------------------------------------ */ -int storage_storageadd(struct map_session_data *sd, int index, int amount) +int storage_storageadd(dumb_ptr<map_session_data> sd, int index, int amount) { struct storage *stor; @@ -219,7 +219,7 @@ int storage_storageadd(struct map_session_data *sd, int index, int amount) * Retrieve an item from the storage. *------------------------------------------ */ -int storage_storageget(struct map_session_data *sd, int index, int amount) +int storage_storageget(dumb_ptr<map_session_data> sd, int index, int amount) { struct storage *stor; PickupFail flag; @@ -249,7 +249,7 @@ int storage_storageget(struct map_session_data *sd, int index, int amount) * Modified By Valaris to save upon closing [massdriller] *------------------------------------------ */ -int storage_storageclose(struct map_session_data *sd) +int storage_storageclose(dumb_ptr<map_session_data> sd) { struct storage *stor; @@ -281,7 +281,7 @@ int storage_storageclose(struct map_session_data *sd) * When quitting the game. *------------------------------------------ */ -int storage_storage_quit(struct map_session_data *sd) +int storage_storage_quit(dumb_ptr<map_session_data> sd) { struct storage *stor; diff --git a/src/map/storage.hpp b/src/map/storage.hpp index 1974efb..8f31517 100644 --- a/src/map/storage.hpp +++ b/src/map/storage.hpp @@ -4,15 +4,17 @@ #ifndef STORAGE_HPP #define STORAGE_HPP -int storage_storageopen(struct map_session_data *sd); -int storage_storageadd(struct map_session_data *sd, int index, int amount); -int storage_storageget(struct map_session_data *sd, int index, int amount); -int storage_storageclose(struct map_session_data *sd); +#include "map.hpp" + +int storage_storageopen(dumb_ptr<map_session_data> sd); +int storage_storageadd(dumb_ptr<map_session_data> sd, int index, int amount); +int storage_storageget(dumb_ptr<map_session_data> sd, int index, int amount); +int storage_storageclose(dumb_ptr<map_session_data> sd); void do_init_storage(void); void do_final_storage(void); struct storage *account2storage(int account_id); struct storage *account2storage2(int account_id); -int storage_storage_quit(struct map_session_data *sd); +int storage_storage_quit(dumb_ptr<map_session_data> sd); int storage_storage_save(int account_id, int final); int storage_storage_saved(int account_id); diff --git a/src/map/tmw.cpp b/src/map/tmw.cpp index 66b8bb9..9740ad8 100644 --- a/src/map/tmw.cpp +++ b/src/map/tmw.cpp @@ -17,14 +17,14 @@ #include "../poison.hpp" static -void tmw_AutoBan(struct map_session_data *sd, const char *reason, int length); +void tmw_AutoBan(dumb_ptr<map_session_data> sd, const char *reason, int length); static -int tmw_CheckChatLameness(struct map_session_data *sd, const char *message); +int tmw_CheckChatLameness(dumb_ptr<map_session_data> sd, const char *message); static int tmw_ShorterStrlen(const char *s1, const char *s2); -int tmw_CheckChatSpam(struct map_session_data *sd, const char *message) +int tmw_CheckChatSpam(dumb_ptr<map_session_data> sd, const char *message) { nullpo_retr(1, sd); TimeT now = TimeT::now(); @@ -86,7 +86,7 @@ int tmw_CheckChatSpam(struct map_session_data *sd, const char *message) return 0; } -void tmw_AutoBan(struct map_session_data *sd, const char *reason, int length) +void tmw_AutoBan(dumb_ptr<map_session_data> sd, const char *reason, int length) { if (length == 0 || sd->auto_ban_info.in_progress) return; @@ -120,7 +120,7 @@ int tmw_ShorterStrlen(const char *s1, const char *s2) } // Returns true if more than 50% of input message is caps or punctuation -int tmw_CheckChatLameness(struct map_session_data *, const char *message) +int tmw_CheckChatLameness(dumb_ptr<map_session_data>, const char *message) { int count, lame; diff --git a/src/map/tmw.hpp b/src/map/tmw.hpp index d64f45e..26446b9 100644 --- a/src/map/tmw.hpp +++ b/src/map/tmw.hpp @@ -2,8 +2,11 @@ #define TMW_HPP #include "../common/const_array.hpp" +#include "../common/dumb_ptr.hpp" -int tmw_CheckChatSpam(struct map_session_data *sd, const char *message); +#include "map.hpp" + +int tmw_CheckChatSpam(dumb_ptr<map_session_data> sd, const char *message); void tmw_GmHackMsg(const_string line); void tmw_TrimStr(char *str); diff --git a/src/map/trade.cpp b/src/map/trade.cpp index ba789c3..ff54caa 100644 --- a/src/map/trade.cpp +++ b/src/map/trade.cpp @@ -17,9 +17,9 @@ * 取引要請を相手に送る *------------------------------------------ */ -void trade_traderequest(struct map_session_data *sd, int target_id) +void trade_traderequest(dumb_ptr<map_session_data> sd, int target_id) { - struct map_session_data *target_sd; + dumb_ptr<map_session_data> target_sd; nullpo_retv(sd); @@ -71,9 +71,9 @@ void trade_traderequest(struct map_session_data *sd, int target_id) * 取引要請 *------------------------------------------ */ -void trade_tradeack(struct map_session_data *sd, int type) +void trade_tradeack(dumb_ptr<map_session_data> sd, int type) { - struct map_session_data *target_sd; + dumb_ptr<map_session_data> target_sd; nullpo_retv(sd); if ((target_sd = map_id2sd(sd->trade_partner)) != NULL) @@ -102,9 +102,9 @@ void trade_tradeack(struct map_session_data *sd, int type) * アイテム追加 *------------------------------------------ */ -void trade_tradeadditem(struct map_session_data *sd, int index, int amount) +void trade_tradeadditem(dumb_ptr<map_session_data> sd, int index, int amount) { - struct map_session_data *target_sd; + dumb_ptr<map_session_data> target_sd; struct item_data *id; int trade_i; int trade_weight = 0; @@ -227,9 +227,9 @@ void trade_tradeadditem(struct map_session_data *sd, int index, int amount) * アイテム追加完了(ok押し) *------------------------------------------ */ -void trade_tradeok(struct map_session_data *sd) +void trade_tradeok(dumb_ptr<map_session_data> sd) { - struct map_session_data *target_sd; + dumb_ptr<map_session_data> target_sd; int trade_i; nullpo_retv(sd); @@ -259,9 +259,9 @@ void trade_tradeok(struct map_session_data *sd) * 取引キャンセル *------------------------------------------ */ -void trade_tradecancel(struct map_session_data *sd) +void trade_tradecancel(dumb_ptr<map_session_data> sd) { - struct map_session_data *target_sd; + dumb_ptr<map_session_data> target_sd; int trade_i; nullpo_retv(sd); @@ -312,9 +312,9 @@ void trade_tradecancel(struct map_session_data *sd) * 取引許諾(trade押し) *------------------------------------------ */ -void trade_tradecommit(struct map_session_data *sd) +void trade_tradecommit(dumb_ptr<map_session_data> sd) { - struct map_session_data *target_sd; + dumb_ptr<map_session_data> target_sd; int trade_i; nullpo_retv(sd); @@ -416,9 +416,9 @@ void trade_tradecommit(struct map_session_data *sd) // This is called when a char's zeny is changed // This helps prevent money duplication and other problems // [Jaxad0127] -void trade_verifyzeny(struct map_session_data *sd) +void trade_verifyzeny(dumb_ptr<map_session_data> sd) { - struct map_session_data *target_sd; + dumb_ptr<map_session_data> target_sd; nullpo_retv(sd); diff --git a/src/map/trade.hpp b/src/map/trade.hpp index 0edca9c..708e578 100644 --- a/src/map/trade.hpp +++ b/src/map/trade.hpp @@ -1,12 +1,14 @@ #ifndef TRADE_HPP #define TRADE_HPP -void trade_traderequest(struct map_session_data *sd, int target_id); -void trade_tradeack(struct map_session_data *sd, int type); -void trade_tradeadditem(struct map_session_data *sd, int index, int amount); -void trade_tradeok(struct map_session_data *sd); -void trade_tradecancel(struct map_session_data *sd); -void trade_tradecommit(struct map_session_data *sd); -void trade_verifyzeny(struct map_session_data *sd); +#include "map.hpp" + +void trade_traderequest(dumb_ptr<map_session_data> sd, int target_id); +void trade_tradeack(dumb_ptr<map_session_data> sd, int type); +void trade_tradeadditem(dumb_ptr<map_session_data> sd, int index, int amount); +void trade_tradeok(dumb_ptr<map_session_data> sd); +void trade_tradecancel(dumb_ptr<map_session_data> sd); +void trade_tradecommit(dumb_ptr<map_session_data> sd); +void trade_verifyzeny(dumb_ptr<map_session_data> sd); #endif // TRADE_HPP |