-
Notifications
You must be signed in to change notification settings - Fork 0
/
dg_misc.cpp
442 lines (403 loc) · 15 KB
/
dg_misc.cpp
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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
/**************************************************************************
* File: dg_misc.c *
* Usage: contains general functions for script usage. *
* *
* *
**************************************************************************/
#include "config.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"
/* copied from spell_parser.c: */
//#define SINFO spell_info[spellnum]
/* external vars */
void die ( Character *ch, Character * killer );
#define IS_SPELL_CAST(tt) (((tt) > 0) && ((tt) < MAX_SKILLS) && (spell_info[tt].type == 1))
/* 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 )
{
Character *caster = NULL;
Character *tch = NULL;
struct obj_data *tobj = NULL;
Room *caster_room = NULL;
char *s, *t;
int spellnum, target = 0;
char buf2[MAX_INPUT_LENGTH], orig_cmd[MAX_INPUT_LENGTH];
/* need to get the caster or the room of the temporary caster */
switch ( type )
{
case MOB_TRIGGER:
caster = ( Character * ) go;
break;
case WLD_TRIGGER:
caster_room = ( Room * ) go;
break;
case OBJ_TRIGGER:
caster_room = dg_room_of_obj ( ( struct obj_data * ) go );
if ( !caster_room )
{
script_log ( "Trigger: %s, VNum %d. dg_do_cast: unknown room for object-caster! Line %d: %s",
GET_TRIG_NAME ( trig ), GET_TRIG_VNUM ( trig ), GET_TRIG_LINE_NR ( trig ), trig->curr_state->cmd );
return;
}
break;
default:
script_log ( "Trigger: %s, VNum %d. dg_do_cast: unknown trigger type! Line %d: %s",
GET_TRIG_NAME ( trig ), GET_TRIG_VNUM ( trig ), GET_TRIG_LINE_NR ( trig ), trig->curr_state->cmd );
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. Line %d: %s",
GET_TRIG_NAME ( trig ), GET_TRIG_VNUM ( trig ), GET_TRIG_LINE_NR ( trig ), trig->curr_state->cmd );
return;
}
s = strtok ( NULL, "'" );
if ( s == NULL )
{
script_log ( "Trigger: %s, VNum %d. dg_cast needs spell name in `'s. Line %d: %s",
GET_TRIG_NAME ( trig ), GET_TRIG_VNUM ( trig ), GET_TRIG_LINE_NR ( trig ), trig->curr_state->cmd );
return;
}
t = strtok ( NULL, "\0" );
/* spellnum = search_block(s, spells, 0); */
spellnum = find_skill_num ( s );
if ( !IS_SPELL_CAST(spellnum) )
{
script_log ( "Trigger: %s, VNum %d. dg_cast: invalid spell name (Line %d: %s)",
GET_TRIG_NAME ( trig ), GET_TRIG_VNUM ( trig ), GET_TRIG_LINE_NR ( 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 (Line %d: %s)",
GET_TRIG_NAME ( trig ), GET_TRIG_VNUM ( trig ), GET_TRIG_LINE_NR ( trig ), orig_cmd );
return;
}
}
if ( IS_SET ( SINFO.routines, MAG_GROUPS ) )
{
script_log ( "Trigger: %s, VNum %d. dg_cast: group spells not permitted (Line %d: %s)",
GET_TRIG_NAME ( trig ), GET_TRIG_VNUM ( trig ), GET_TRIG_LINE_NR ( trig ), orig_cmd );
return;
}
if ( IS_SET ( SINFO.targets, TAR_AREA_DIR ) )
{
script_log ( "Trigger: %s, VNum %d. dg_cast: directional spells not permitted (Line %d: %s)",
GET_TRIG_NAME ( trig ), GET_TRIG_VNUM ( trig ), GET_TRIG_LINE_NR ( trig ), orig_cmd );
return;
}
if ( !caster )
{
if ( type == OBJ_TRIGGER )
{
obj_data *obj = (obj_data *) go;
if ( obj->in_obj )
obj = obj->in_obj;
if ( obj->carried_by )
{
call_magic ( obj->carried_by, tch, tobj, ( char * ) "", spellnum, DG_SPELL_LEVEL, CAST_SPELL );
return;
}
if ( obj->worn_by )
{
call_magic ( obj->worn_by, tch, tobj, ( char * ) "", spellnum, DG_SPELL_LEVEL, CAST_SPELL );
return;
}
}
caster = read_mobile ( DG_CASTER_PROXY );
if ( !caster )
{
script_log ( "Trigger: %s, VNum %d. dg_cast: Cannot load the caster mob! (Line %d: %s)",
GET_TRIG_NAME ( trig ), GET_TRIG_VNUM ( trig ), GET_TRIG_LINE_NR ( trig ), orig_cmd );
return;
}
caster->free_non_proto_strings();
/* set the caster's name to that of the object, or the gods.... */
if ( type==OBJ_TRIGGER )
{
caster->player.short_descr = strdup ( ( ( struct obj_data * ) go )->short_description );
}
else if ( type==WLD_TRIGGER )
{
caster->player.short_descr = strdup ( "The gods" );
}
char_to_room ( caster, caster_room );
/*
caster->next_in_room = caster_room->people;
caster_room->people = caster;
caster->in_room = real_room(caster_room->number);
*/
call_magic ( caster, tch, tobj, ( char * ) "", spellnum, DG_SPELL_LEVEL, CAST_SPELL );
caster->free_non_proto_strings();
extract_char ( caster );
}
else
call_magic ( caster, tch, tobj, ( char * ) "", spellnum, GET_LEVEL ( caster ), CAST_SPELL );
}
/* 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: dg_affect <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 )
{
Character *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_p[MAX_INPUT_LENGTH], duration_p[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_p, duration_p );
/* make sure all parameters are present */
if ( !*charname || !*property || !*value_p || !*duration_p )
{
script_log ( "Trigger: %s, VNum %d. dg_affect usage: <target> <property> <value> <duration>. Line %d: %s",
GET_TRIG_NAME ( trig ), GET_TRIG_VNUM ( trig ), GET_TRIG_LINE_NR ( trig ), cmd );
return;
}
value = atoi ( value_p );
duration = atoi ( duration_p );
if ( duration <= 0 )
{
script_log ( "Trigger: %s, VNum %d. dg_affect: need positive duration! Line %d: %s",
GET_TRIG_NAME ( trig ), GET_TRIG_VNUM ( trig ), GET_TRIG_LINE_NR ( trig ), cmd );
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'! Line %d: %s",
GET_TRIG_NAME ( trig ), GET_TRIG_VNUM ( trig ), property, GET_TRIG_LINE_NR ( trig ), cmd );
return;
}
/* locate the target */
ch = get_char ( charname );
if ( !ch )
{
script_log ( "Trigger: %s, VNum %d. dg_affect: cannot locate target '%s'! Line %d: %s",
GET_TRIG_NAME ( trig ), GET_TRIG_VNUM ( trig ), charname, GET_TRIG_LINE_NR ( trig ), cmd );
return;
}
if ( !str_cmp ( value_p, "off" ) )
{
affect_from_char ( ch, SPELL_DG_AFFECT, i );
return;
}
/* add the affect */
af.type = SPELL_DG_AFFECT;
af.expire = sec_to_time ( 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 );
}
/* 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 ( Character *ch, int allow_gods )
{
if ( !ch )
return FALSE;
else if ( IS_NPC ( ch ) )
return TRUE; /* all npcs are allowed as targets */
else if ( GET_LEVEL ( ch ) < LVL_IMMORT )
return TRUE; /* as well as all mortals */
else if ( !allow_gods && GET_LEVEL ( ch ) >= LVL_IMMORT )
return FALSE; /* but not always the highest gods */
else if ( !PRF_FLAGGED ( ch, PRF_NOHASSLE )
&& GET_INVIS_LEV ( ch ) < LVL_IMMORT )
return TRUE; /* the ones in between as allowed as long as they're visible,
* and have no-hassle off. */
else
return FALSE; /* The rest are gods with nohassle on... */
}
/* Add or remove a destination for a mob or an object *
* to the end of their destination list. *
* usage: dg_dest (add/remove) <room vnum/all> <target> *
* Jamie Nelson - mordecai@xtra.co.nz (3rd mar 04) */
void do_dg_destination ( void *go, struct script_data *sc, trig_data *trig,
int script_type, char *cmd )
{
Character *ch = NULL, *c = NULL;
obj_data *obj = NULL, *o = NULL;
Room *room = NULL;
char junk[MAX_INPUT_LENGTH]; /* will be set to "dg_affect" */
char addrem[MAX_INPUT_LENGTH], dest[MAX_INPUT_LENGTH];
char name[MAX_INPUT_LENGTH];
room_rnum loc = NULL;
int all = FALSE;
int add = 0;
half_chop ( cmd, junk, cmd );
half_chop ( cmd, addrem, cmd );
half_chop ( cmd, dest, cmd );
half_chop ( cmd, name, cmd );
/* make sure all parameters are present */
if ( !*addrem || !*dest || !*name )
{
script_log ( "Trigger: %s, VNum %d. dg_dest (add/remove) <room vnum/ALL> <target>. Line %d: %s",
GET_TRIG_NAME ( trig ), GET_TRIG_VNUM ( trig ), GET_TRIG_LINE_NR ( trig ), cmd );
return;
}
if ( !strcasecmp ( dest, "all" ) )
all = TRUE;
else if ( !is_number ( dest ) || ( loc = real_room ( atoi ( dest ) ) ) == NULL )
{
script_log ( "Trigger: %s, VNum %d. dg_dest: invalid target room! Line %d: %s",
GET_TRIG_NAME ( trig ), GET_TRIG_VNUM ( trig ), GET_TRIG_LINE_NR ( trig ), cmd );
return;
}
if ( !strcmp ( addrem, "add" ) )
add = TRUE;
else if ( !strcmp ( addrem, "remove" ) )
add = FALSE;
else
{
script_log ( "Trigger: %s, VNum %d. dg_dest: need to specify add or remove for second argument! Line %d: %s",
GET_TRIG_NAME ( trig ), GET_TRIG_VNUM ( trig ), GET_TRIG_LINE_NR ( trig ), cmd );
return;
}
if ( all && add )
{
script_log ( "Trigger: %s, VNum %d. dg_dest: can only use ALL with remove! Line %d: %s",
GET_TRIG_NAME ( trig ), GET_TRIG_VNUM ( trig ), GET_TRIG_LINE_NR ( trig ), cmd );
return;
}
/* locate target */
switch ( script_type )
{
case MOB_TRIGGER:
ch = ( Character * ) go;
if ( !strcmp ( name, "self" ) )
c = ch;
else if ( ( o = get_object_in_equip ( ch, name ) ) )
;
else if ( ( o = get_obj_in_list ( name, ch->carrying ) ) )
;
else if ( ( c = get_char_room ( name, NULL, IN_ROOM ( ch ) ) ) )
;
else if ( ( o = get_obj_in_list ( name,IN_ROOM ( ch )->contents ) ) )
;
else if ( ( c = get_char ( name ) ) )
;
else if ( ( o = get_obj ( name ) ) ) {}
break;
case OBJ_TRIGGER:
obj = ( obj_data * ) go;
if ( !strcmp ( name, "self" ) )
o = obj;
else if ( ( c = get_char_by_obj ( obj, name ) ) )
;
else if ( ( o = get_obj_by_obj ( obj, name ) ) ) {}
break;
case WLD_TRIGGER:
room = ( Room * ) go;
if ( ( c = get_char_by_room ( room, name ) ) )
;
else if ( ( o = get_obj_by_room ( room, name ) ) ) {}
break;
}
if ( c )
{
if ( add )
add_travel_point_by_pointer ( &TRAVEL_LIST ( c ), loc->number );
else
remove_travel_point_by_dest ( &TRAVEL_LIST ( c ), loc->number );
}
else if ( o )
{
if ( add )
add_travel_point_by_pointer ( &TRAVEL_LIST ( o ), loc->number );
else
remove_travel_point_by_dest ( &TRAVEL_LIST ( o ), loc->number );
}
return;
}