summaryrefslogtreecommitdiff
path: root/src/emap/scriptdefines.h
blob: 69b6e3c9a528f6695819aa5f21d8875633778b9a (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
// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL.
// Copyright (c) 2014 - 2015 Evol developers

#ifndef EVOL_MAP_SCRIPTDEFINES
#define EVOL_MAP_SCRIPTDEFINES

#define getSessionDataReturn(def) \
    if (!st->rid) \
    { \
        ShowWarning("!st->rid\n"); \
        script->reportsrc(st); \
        script_pushint(st, def); \
        return false; \
    } \
    TBL_PC *sd = script->rid2sd(st); \
    if (!sd) \
    { \
        ShowWarning("player not attached\n"); \
        script->reportsrc(st); \
        script_pushint(st, def); \
        return false; \
    } \
    struct SessionExt *data = session_get(sd->fd)

#define getSessionData(data) \
    if (!st->rid) \
    { \
        ShowWarning("!st->rid\n"); \
        script->reportsrc(st); \
        return false; \
    } \
    TBL_PC *sd = script->rid2sd(st); \
    if (!sd) \
    { \
        ShowWarning("player not attached\n"); \
        script->reportsrc(st); \
        return false; \
    } \
    struct SessionExt *data = session_get(sd->fd)

#define getMapData(m) \
        struct MapdExt *mapData = mapd_get(m); \
        if (!mapData) \
        { \
            ShowWarning("cant get map data\n"); \
            script->reportsrc(st); \
            return false; \
        }

#define getMapDataReturn(m, def) \
        struct MapdExt *mapData = mapd_get(m); \
        if (!mapData) \
        { \
            ShowWarning("cant get map data\n"); \
            script->reportsrc(st); \
            script_pushint(st, def); \
            return false; \
        }

#define getSD() \
    TBL_PC *sd = script->rid2sd(st); \
    if (!sd) \
    { \
        ShowWarning("player not attached\n"); \
        script->reportsrc(st); \
        return false; \
    }

#define getSDReturn(def) \
    TBL_PC *sd = script->rid2sd(st); \
    if (!sd) \
    { \
        ShowWarning("player not attached\n"); \
        script->reportsrc(st); \
        script_pushint(st, def); \
        return false; \
    }

#define getInventoryIndex(idx) \
    const int n = script_getnum(st, idx); \
    if (n < 0 || n >= MAX_INVENTORY) \
    { \
        ShowWarning("Wrong inventory index\n"); \
        script->reportsrc(st); \
        return false; \
    }

#define getND() \
    TBL_NPC *nd = map->id2nd(st->oid); \
    if (!nd) \
        return; \

#define getNDReturn(def) \
    TBL_NPC *nd = map->id2nd(st->oid); \
    if (!nd) \
        return def; \

#endif  // EVOL_MAP_SCRIPTDEFINES