From 2b6f23670b3add2cb845b9606d13e6aad6360f11 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 3 Oct 2015 00:46:44 +0300 Subject: Add basic support for own collision types. --- src/emap/init.c | 3 +++ src/emap/map.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/emap/map.h | 6 +++++ 3 files changed, 88 insertions(+) diff --git a/src/emap/init.c b/src/emap/init.c index 09f3c1e..beff644 100644 --- a/src/emap/init.c +++ b/src/emap/init.c @@ -177,6 +177,9 @@ HPExport void plugin_init (void) addHookPre("unit->can_move", eunit_can_move); addHookPre("unit->walktoxy", eunit_walktoxy); addHookPre("mail->invalid_operation", email_invalid_operation); + addHookPre("map->cell2gat", emap_cell2gat); + addHookPre("map->gat2cell", emap_gat2cell); + addHookPre("map->getcellp", emap_getcellp); addHookPre("script->set_reg_npc_num", eset_reg_npcscope_num); addHookPre("script->get_val_npc_num", eget_val_npcscope_num); addHookPre("script->get_val_ref_num", eget_val_npcscope_num); diff --git a/src/emap/map.c b/src/emap/map.c index fc5e37d..97aa464 100644 --- a/src/emap/map.c +++ b/src/emap/map.c @@ -134,3 +134,82 @@ void emap_online_list(int fd) send_online_list(fd, buf, ptr - buf); aFree(buf); } + +int emap_getcellp(struct map_data* m, + const struct block_list *bl, + int16 *xPtr, int16 *yPtr, + cell_chk *cellchkPtr) +{ + if (bl) + { + const cell_chk cellchk = *cellchkPtr; + if (cellchk == CELL_CHKWALL || + cellchk == CELL_CHKPASS || + cellchk == CELL_CHKNOPASS || + cellchk == CELL_CHKNOREACH) + { + if (bl->type == BL_NPC) + { + } + } + } + return 0; +} + +struct mapcell emap_gat2cell(int *gatPtr) +{ + struct mapcell cell; + const int gat = *gatPtr; + + memset(&cell, 0, sizeof(struct mapcell)); + + switch (gat) + { + case 0: // walkable ground + cell.walkable = 1; + cell.shootable = 1; + cell.water = 0; + break; + case 1: // wall + cell.walkable = 0; + cell.shootable = 0; + cell.water = 0; + break; + case 2: // air allowed + cell.walkable = 0; + cell.shootable = 0; + cell.water = 0; + break; + case 3: // unwalkable water + cell.walkable = 0; + cell.shootable = 1; + cell.water = 1; + break; + case 4: // sit, walkable ground + cell.walkable = 1; + cell.shootable = 1; + cell.water = 0; + break; + default: + ShowWarning("map_gat2cell: unrecognized gat type '%d'\n", gat); + break; + } + + hookStop(); + return cell; +} + +int emap_cell2gat(struct mapcell *cellPtr) +{ + struct mapcell cell = *cellPtr; + hookStop(); + if (cell.walkable == 1 && cell.shootable == 1 && cell.water == 0) + return 0; + if (cell.walkable == 0 && cell.shootable == 0 && cell.water == 0) + return 1; + if (cell.walkable == 0 && cell.shootable == 1 && cell.water == 1) + return 3; + + ShowWarning("map_cell2gat: cell has no matching gat type\n"); + return 1; +} diff --git a/src/emap/map.h b/src/emap/map.h index cd8dac8..5c6e899 100644 --- a/src/emap/map.h +++ b/src/emap/map.h @@ -16,5 +16,11 @@ int emap_addflooritem_post(int retVal, int *third_charid, int *flags); void emap_online_list(int fd); +int emap_getcellp(struct map_data* m, + const struct block_list *bl, + int16 *xPtr, int16 *yPtr, + cell_chk *cellchkPtr); +struct mapcell emap_gat2cell(int *gatPtr); +int emap_cell2gat(struct mapcell *cellPtr); #endif // EVOL_MAP_MAP -- cgit v1.2.3-70-g09d2