diff options
author | skyleo <skyleo@skyleo.de> | 2019-09-08 02:53:24 +0200 |
---|---|---|
committer | Haru <haru@dotalux.com> | 2020-03-08 20:56:27 +0100 |
commit | d13b24a62ac933364839c7ece1f70eba001e7c2d (patch) | |
tree | c10d9f953cf017579a22c9d58b9fc74fefc2956e /src/map/script.c | |
parent | feb1f9d96a9cfc12602c96235106397b67f2aeb4 (diff) | |
download | hercules-d13b24a62ac933364839c7ece1f70eba001e7c2d.tar.gz hercules-d13b24a62ac933364839c7ece1f70eba001e7c2d.tar.bz2 hercules-d13b24a62ac933364839c7ece1f70eba001e7c2d.tar.xz hercules-d13b24a62ac933364839c7ece1f70eba001e7c2d.zip |
Refactor code using directions to use enum unit_dir
This removes a lot of duplicated code, especially related to people not using the arrays dirx and diry.
Assertions for whenever these arrays are used have been added as well, to ensure valid index range.
Some trailing white space has been removed as well.
Diffstat (limited to 'src/map/script.c')
-rw-r--r-- | src/map/script.c | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/src/map/script.c b/src/map/script.c index 0e30708d9..28d06a8f1 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -19727,7 +19727,7 @@ static BUILDIN(setunitdata) clif->changelook(bl, LOOK_WEAPON, val); break; case UDT_LOOKDIR: - unit->setdir(bl, (uint8) val); + unit->setdir(bl, (enum unit_dir) val); break; case UDT_CANMOVETICK: md->ud.canmove_tick = val; @@ -19859,7 +19859,7 @@ static BUILDIN(setunitdata) status->calc_misc(bl, &hd->base_status, hd->homunculus.level); break; case UDT_LOOKDIR: - unit->setdir(bl, (unsigned char) val); + unit->setdir(bl, (enum unit_dir) val); break; case UDT_CANMOVETICK: hd->ud.canmove_tick = val; @@ -19998,7 +19998,7 @@ static BUILDIN(setunitdata) status->calc_misc(bl, &pd->status, pd->pet.level); break; case UDT_LOOKDIR: - unit->setdir(bl, (unsigned char) val); + unit->setdir(bl, (enum unit_dir) val); break; case UDT_CANMOVETICK: pd->ud.canmove_tick = val; @@ -20131,7 +20131,7 @@ static BUILDIN(setunitdata) status->calc_misc(bl, &mc->base_status, mc->db->lv); break; case UDT_LOOKDIR: - unit->setdir(bl, (unsigned char) val); + unit->setdir(bl, (enum unit_dir) val); break; case UDT_CANMOVETICK: mc->ud.canmove_tick = val; @@ -20265,7 +20265,7 @@ static BUILDIN(setunitdata) status->calc_misc(bl, &ed->base_status, ed->db->lv); break; case UDT_LOOKDIR: - unit->setdir(bl, (unsigned char) val); + unit->setdir(bl, (enum unit_dir) val); break; case UDT_CANMOVETICK: ed->ud.canmove_tick = val; @@ -20397,7 +20397,7 @@ static BUILDIN(setunitdata) status->calc_misc(bl, &nd->status, nd->level); break; case UDT_LOOKDIR: - unit->setdir(bl, (unsigned char) val); + unit->setdir(bl, (enum unit_dir) val); break; case UDT_STR: nd->status.str = (unsigned short) val; @@ -23250,7 +23250,6 @@ static BUILDIN(progressbar_unit) } static BUILDIN(pushpc) { - uint8 dir; int cells, dx, dy; struct map_session_data* sd; @@ -23259,14 +23258,14 @@ static BUILDIN(pushpc) return true; } - dir = script_getnum(st,2); - cells = script_getnum(st,3); + enum unit_dir dir = script_getnum(st, 2); + cells = script_getnum(st,3); - if (dir > 7) { + if (dir >= UNIT_DIR_MAX) { ShowWarning("buildin_pushpc: Invalid direction %d specified.\n", dir); script->reportsrc(st); - dir%= 8; // trim spin-over + dir %= UNIT_DIR_MAX; // trim spin-over } if(!cells) @@ -23275,10 +23274,11 @@ static BUILDIN(pushpc) } else if(cells<0) {// pushing backwards - dir = (dir+4)%8; // turn around - cells = -cells; + dir = unit_get_opposite_dir(dir); + cells = -cells; } + Assert_retr(false, dir >= UNIT_DIR_FIRST && dir < UNIT_DIR_MAX); dx = dirx[dir]; dy = diry[dir]; |