-
Notifications
You must be signed in to change notification settings - Fork 0
/
dg_misc.c
323 lines (284 loc) · 10.3 KB
/
dg_misc.c
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
/**************************************************************************
* File: dg_misc.c *
* Usage: contains general functions for script usage. *
* *
* $Author: Mark A. Heilpern/egreen/Welcor $ *
* $Date: 2004/10/11 12:07:00$ *
* $Revision: 1.0.14 $ *
**************************************************************************/
#include "conf.h"
#include "sysdep.h"
#include "structs.h"
#include "dg_scripts.h"
#include "utils.h"
#include "comm.h"
#include "interpreter.h"
#include "handler.h"
#include "dg_event.h"
#include "db.h"
#include "screen.h"
#include "spells.h"
#include "constants.h"
SVNHEADER("$Id: dg_misc.c 55 2009-03-20 17:58:56Z pladow $");
void die(struct char_data *ch, struct char_data * killer);
/* external vars */
extern struct spell_info_type spell_info[];
/* cast a spell; can be called by mobiles, objects and rooms, and no */
/* level check is required. Note that mobs should generally use the */
/* normal 'cast' command (which must be patched to allow mobs to cast */
/* spells) as the spell system is designed to have a character caster, */
/* and this cast routine may overlook certain issues. */
/* LIMITATION: a target MUST exist for the spell unless the spell is */
/* set to TAR_IGNORE. Also, group spells are not permitted */
/* code borrowed from do_cast() */
void do_dg_cast(void *go, struct script_data *sc, trig_data *trig,
int type, char *cmd)
{
struct char_data *caster = NULL;
struct char_data *tch = NULL;
struct obj_data *tobj = NULL;
struct room_data *caster_room = NULL;
char *s, *t;
int spellnum, target = 0;
char buf2[MAX_STRING_LENGTH], orig_cmd[MAX_INPUT_LENGTH];
/* need to get the caster or the room of the temporary caster */
switch (type) {
case MOB_TRIGGER:
caster = (struct char_data *)go;
break;
case WLD_TRIGGER:
caster_room = (struct room_data *)go;
break;
case OBJ_TRIGGER:
caster_room = dg_room_of_obj((struct obj_data *)go);
if (!caster_room) {
script_log("dg_do_cast: unknown room for object-caster!");
return;
}
break;
default:
script_log("dg_do_cast: unknown trigger type!");
return;
}
strcpy(orig_cmd, cmd);
/* get: blank, spell name, target name */
s = strtok(cmd, "'");
if (s == NULL) {
script_log("Trigger: %s, VNum %d. dg_cast needs spell name.",
GET_TRIG_NAME(trig), GET_TRIG_VNUM(trig));
return;
}
s = strtok(NULL, "'");
if (s == NULL) {
script_log("Trigger: %s, VNum %d. dg_cast needs spell name in `'s.",
GET_TRIG_NAME(trig), GET_TRIG_VNUM(trig));
return;
}
t = strtok(NULL, "\0");
/* spellnum = search_block(s, spells, 0); */
spellnum = find_skill_num(s, SKTYPE_SPELL);
if ((spellnum < 1) || (spellnum >= SKILL_TABLE_SIZE || (!IS_SET(skill_type(spellnum), SKTYPE_SPELL)))) {
script_log("Trigger: %s, VNum %d. dg_cast: invalid spell name (%s)",
GET_TRIG_NAME(trig), GET_TRIG_VNUM(trig), orig_cmd);
return;
}
/* Find the target */
if (t != NULL) {
one_argument(strcpy(buf2, t), t);
skip_spaces(&t);
}
if (IS_SET(SINFO.targets, TAR_IGNORE)) {
target = TRUE;
} else if (t != NULL && *t) {
if (!target &&
(IS_SET(SINFO.targets, TAR_CHAR_ROOM) ||
IS_SET(SINFO.targets, TAR_CHAR_WORLD))) {
if ((tch = get_char(t)) != NULL)
target = TRUE;
}
if (!target &&
(IS_SET(SINFO.targets, TAR_OBJ_INV) ||
IS_SET(SINFO.targets, TAR_OBJ_EQUIP) ||
IS_SET(SINFO.targets, TAR_OBJ_ROOM) ||
IS_SET(SINFO.targets, TAR_OBJ_WORLD))) {
if ((tobj = get_obj(t)) != NULL)
target = TRUE;
}
if (!target) {
script_log("Trigger: %s, VNum %d. dg_cast: target not found (%s)",
GET_TRIG_NAME(trig), GET_TRIG_VNUM(trig), orig_cmd);
return;
}
}
if (IS_SET(SINFO.routines, MAG_GROUPS)) {
script_log("Trigger: %s, VNum %d. dg_cast: group spells not permitted (%s)",
GET_TRIG_NAME(trig), GET_TRIG_VNUM(trig), orig_cmd);
return;
}
if (!caster) {
caster = read_mobile(DG_CASTER_PROXY, VIRTUAL);
if (!caster) {
script_log("dg_cast: Cannot load the caster mob!");
return;
}
/* set the caster's name to that of the object, or the gods.... */
if (type==OBJ_TRIGGER)
caster->short_descr =
strdup(((struct obj_data *)go)->short_description);
else if (type==WLD_TRIGGER)
caster->short_descr = strdup("The gods");
caster->next_in_room = caster_room->people;
caster_room->people = caster;
IN_ROOM(caster) = real_room(caster_room->number);
call_magic(caster, tch, tobj, spellnum, DG_SPELL_LEVEL, CAST_SPELL, t);
extract_char(caster);
} else
call_magic(caster, tch, tobj, spellnum, GET_LEVEL(caster), CAST_SPELL, t);
}
/* modify an affection on the target. affections can be of the AFF_x */
/* variety or APPLY_x type. APPLY_x's have an integer value for them */
/* while AFF_x's have boolean values. In any case, the duration MUST */
/* be non-zero. */
/* usage: apply <target> <property> <value> <duration> */
#define APPLY_TYPE 1
#define AFFECT_TYPE 2
void do_dg_affect(void *go, struct script_data *sc, trig_data *trig,
int script_type, char *cmd)
{
struct char_data *ch = NULL;
int value=0, duration=0;
char junk[MAX_INPUT_LENGTH]; /* will be set to "dg_affect" */
char charname[MAX_INPUT_LENGTH], property[MAX_INPUT_LENGTH];
char value_s[MAX_INPUT_LENGTH], duration_s[MAX_INPUT_LENGTH];
int i=0, type=0;
struct affected_type af;
half_chop(cmd, junk, cmd);
half_chop(cmd, charname, cmd);
half_chop(cmd, property, cmd);
half_chop(cmd, value_s, duration_s);
/* make sure all parameters are present */
if (!*charname || !*property || !*value_s || !*duration_s) {
script_log("Trigger: %s, VNum %d. dg_affect usage: <target> <property> <value> <duration>",
GET_TRIG_NAME(trig), GET_TRIG_VNUM(trig));
return;
}
value = atoi(value_s);
duration = atoi(duration_s);
if (duration <= 0) {
script_log("Trigger: %s, VNum %d. dg_affect: need positive duration!",
GET_TRIG_NAME(trig), GET_TRIG_VNUM(trig));
script_log("Line was: dg_affect %s %s %s %s (%d)",
charname, property, value_s, duration_s, duration);
return;
}
/* find the property -- first search apply_types */
i = 0;
while (str_cmp(apply_types[i], "\n")) {
if (!str_cmp(apply_types[i], property)) {
type=APPLY_TYPE;
break;
}
i++;
}
if (!type) { /* search affect_types now */
i = 0;
while (str_cmp(affected_bits[i], "\n")) {
if (!str_cmp(affected_bits[i], property)) {
type=AFFECT_TYPE;
break;
}
i++;
}
}
if (!type) { /* property not found */
script_log("Trigger: %s, VNum %d. dg_affect: unknown property '%s'!",
GET_TRIG_NAME(trig), GET_TRIG_VNUM(trig), property);
return;
}
/* locate the target */
ch = get_char(charname);
if (!ch) {
script_log("Trigger: %s, VNum %d. dg_affect: cannot locate target!",
GET_TRIG_NAME(trig), GET_TRIG_VNUM(trig));
return;
}
if (!str_cmp(value_s, "off")) {
affect_from_char(ch, SPELL_DG_AFFECT);
return;
}
/* add the affect */
af.type = SPELL_DG_AFFECT;
af.duration = duration;
af.modifier = value;
if (type == APPLY_TYPE) {
af.location = i;
af.bitvector = 0;
} else {
af.location = 0;
af.bitvector = i;
}
affect_to_char(ch, &af);
}
void send_char_pos(struct char_data *ch, int dam)
{
switch (GET_POS(ch)) {
case POS_MORTALLYW:
act("$n is mortally wounded, and will die soon, if not aided.", TRUE, ch, 0, 0, TO_ROOM);
send_to_char(ch, "You are mortally wounded, and will die soon, if not aided.\r\n");
break;
case POS_INCAP:
act("$n is incapacitated and will slowly die, if not aided.", TRUE, ch, 0, 0, TO_ROOM);
send_to_char(ch, "You are incapacitated and will slowly die, if not aided.\r\n");
break;
case POS_STUNNED:
act("$n is stunned, but will probably regain consciousness again.", TRUE, ch, 0, 0, TO_ROOM);
send_to_char(ch, "You're stunned, but will probably regain consciousness again.\r\n");
break;
case POS_DEAD:
act("$n is dead! R.I.P.", FALSE, ch, 0, 0, TO_ROOM);
send_to_char(ch, "You are dead! Sorry...\r\n");
break;
default: /* >= POSITION SLEEPING */
if (dam > (GET_MAX_HIT(ch) >> 2))
act("That really did HURT!", FALSE, ch, 0, 0, TO_CHAR);
if (GET_HIT(ch) < (GET_MAX_HIT(ch) >> 2))
send_to_char(ch, "@rYou wish that your wounds would stop BLEEDING so much!@n\r\n");
}
}
/* Used throughout the xxxcmds.c files for checking if a char
* can be targetted
* - allow_gods is false when called by %force%, for instance,
* while true for %teleport%. -- Welcor
*/
int valid_dg_target(struct char_data *ch, int bitvector)
{
if (IS_NPC(ch))
return TRUE; /* all npcs are allowed as targets */
else if (GET_ADMLEVEL(ch) < ADMLVL_IMMORT)
return TRUE; /* as well as all mortals */
else if (!IS_SET(bitvector, DG_ALLOW_GODS) &&
GET_ADMLEVEL(ch) >= ADMLVL_GRGOD) /* LVL_GOD has the advance command. Can't allow them to be forced. */
return FALSE; /* but not always the highest gods */
else if (!PRF_FLAGGED(ch, PRF_NOHASSLE))
return TRUE; /* the ones in between as allowed as long as they have no-hassle off. */
else
return FALSE; /* The rest are gods with nohassle on... */
}
void script_damage(struct char_data *vict, int dam)
{
if (ADM_FLAGGED(vict, ADM_NODAMAGE) && (dam > 0)) {
send_to_char(vict, "Being the cool immortal you are, you sidestep a trap,\r\n"
"obviously placed to kill you.\r\n");
return;
}
GET_HIT(vict) -= dam;
GET_HIT(vict) = MIN(GET_HIT(vict), GET_MAX_HIT(vict));
update_pos(vict);
send_char_pos(vict, dam);
if (GET_POS(vict) == POS_DEAD) {
if (!IS_NPC(vict))
mudlog( BRF, 0, TRUE, "%s killed by script at %s",
GET_NAME(vict), world[IN_ROOM(vict)].name);
die(vict, NULL);
}
}