summaryrefslogtreecommitdiff
path: root/src/emap/scriptdefines.h
blob: 69c69b0af826cd8ab6abbe6ba4d71582dfd1c330 (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// 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(data, 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 getSessionDataReturnS(data, def) \
    if (!st->rid) \
    { \
        ShowWarning("!st->rid\n"); \
        script->reportsrc(st); \
        script_pushstr(st, aStrdup(def)); \
        return false; \
    } \
    TBL_PC *sd = script->rid2sd(st); \
    if (!sd) \
    { \
        ShowWarning("player not attached\n"); \
        script->reportsrc(st); \
        script_pushstr(st, aStrdup(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 getSDReturnS(def) \
    TBL_PC *sd = script->rid2sd(st); \
    if (!sd) \
    { \
        ShowWarning("player not attached\n"); \
        script->reportsrc(st); \
        script_pushstr(st, aStrdup(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; \

#define script_pushlabel(st, val) \
    (script->push_val((st)->stack, C_POS, (val),NULL))

#endif  // EVOL_MAP_SCRIPTDEFINES