summaryrefslogtreecommitdiff
path: root/src/map/npc.c
blob: 8ad68af34b77c375059acf742e482433e2673f27 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL.
// Copyright (c) 2014 Evol developers

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "../../../common/HPMi.h"
#include "../../../common/malloc.h"
#include "../../../common/mmo.h"
#include "../../../common/socket.h"
#include "../../../common/strlib.h"
#include "../../../map/map.h"
#include "../../../map/npc.h"
#include "../../../map/pc.h"

#include "map/data/mapd.h"
#include "map/data/npcd.h"
#include "map/struct/mapdext.h"
#include "map/struct/npcdext.h"
#include "map/npc.h"

struct npc_data* enpc_checknear(struct map_session_data* sd, struct block_list* bl)
{
    struct npc_data *nd;

    hookStop();

    if (!sd)
        return NULL;

    if (bl == NULL)
        return NULL;
    if (bl->type != BL_NPC)
        return NULL;
    nd = (TBL_NPC*)bl;

    if (sd->npc_id == bl->id)
        return nd;

    if (nd->class_ < 0) //Class-less npc, enable click from anywhere.
        return nd;

    const int npcX = bl->x;
    const int npcY = bl->y;
    const int x = sd->bl.x;
    const int y = sd->bl.y;

    if (bl->m != sd->bl.m
        || npcX < x - AREA_SIZE - 1 || npcX > x + AREA_SIZE + 1
        || npcY < y - AREA_SIZE - 1 || npcY > y + AREA_SIZE + 1)
    {
        return NULL;
    }

    struct NpcdExt *data = npcd_get(nd);
    if (data)
    {
        const int size = data->areaSize;
        if (npcX < x - size || npcX > x + size
            || npcY < y - size || npcY > y + size)
        {
            return NULL;
        }
    }

    return nd;
}

void enpc_parse_unknown_mapflag(const char *name, char *w3, char *w4, const char* start,
                                const char* buffer, const char* filepath, int *retval)
{
    hookStop();
    if (!strcmpi(w3, "invisible"))
    {
        int16 m = map->mapname2mapid(name);
        struct MapdExt *data = mapd_get(m);
        if (data)
            data->invisible = true;
    }
    else if (!strcmpi(w3, "mask"))
    {
        int16 m = map->mapname2mapid(name);
        struct MapdExt *data = mapd_get(m);
        if (data)
            data->mask = atoi(w4);
    }
    else if (!strcmpi(w3, "nopve"))
    {
        int16 m = map->mapname2mapid(name);
        struct MapdExt *data = mapd_get(m);
        if (data)
            data->flag.nopve = 1;
    }
    else
    {
        ShowError("npc_parse_mapflag: unrecognized mapflag '%s' in file '%s', line '%d'.\n", w3, filepath, strline(buffer,start-buffer));
        if (retval)
            *retval = EXIT_FAILURE;
    }
}