ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/loader.l
Revision: 1.8
Committed: Sat Aug 26 08:44:04 2006 UTC (17 years, 9 months ago) by root
Branch: MAIN
Changes since 1.7: +6 -2 lines
Log Message:
many, many cleanups

File Contents

# Content
1 %{
2 /*
3 * static char *rcsid_object_c =
4 * "$Id$";
5 */
6
7 /*
8 CrossFire, A Multiplayer game for X-windows
9
10 Copyright (C) 2002 Mark Wedel & Crossfire Development Team
11 Copyright (C) 1992 Frank Tore Johansen
12
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26
27 The authors can be reached via e-mail at crossfire-devel@real-time.com
28 */
29
30 /* Eneq(@csd.uu.se): Added weight-modifiers in environment of objects.
31 sub/add_weight will transcend the environment updating the carrying
32 variable. */
33
34
35 #include <global.h>
36 #include <loader.h>
37 #include <newserver.h>
38 #include <sproto.h>
39
40 #define YY_DECL int lex_load(object *op, int map_flags)
41
42 static char *yval();
43
44 static int lex_error;
45 static char msgbuf[65536];
46 static char lorebuf[65536];
47
48 /* Maps the MOVE_* values to names */
49 static const char *const move_name[] = {"walk", "fly_low", "fly_high", "swim", "boat",
50 NULL};
51
52 /* This table is only necessary to convert objects that existed before the
53 * spell object conversion to the new object. It was not practical
54 * to go through every mapping looking for every potion, rod, wand, etc
55 * that had a sp set and update to the new value. So this maps the
56 * old spell numbers to the name of the new archs.
57 * If you are adding a new spell, you should not modify this - you
58 * new spell won't have been used, and thus won't have any legacy object.
59 * NULL entries in this table are valid - to denote objects that should
60 * not be updated for whatever reason.
61 */
62 const char *spell_mapping[] = {
63 "spell_magic_bullet", /* 0 */
64 "spell_small_fireball", /* 1 */
65 "spell_medium_fireball", /* 2 */
66 "spell_large_fireball", /* 3 */
67 "spell_burning_hands", /* 4 */
68 "spell_sm_lightning", /* 5 */
69 "spell_large_lightning", /* 6 */
70 "spell_magic_missile", /* 7 */
71 "spell_create_bomb", /* 8 */
72 "spell_summon_golem", /* 9 */
73 "spell_summon_fire_elemental", /* 10 */
74 "spell_summon_earth_elemental", /* 11 */
75 "spell_summon_water_elemental", /* 12 */
76 "spell_summon_air_elemental", /* 13 */
77 "spell_dimension_door", /* 14 */
78 "spell_create_earth_wall", /* 15 */
79 "spell_paralyze", /* 16 */
80 "spell_icestorm", /* 17 */
81 "spell_magic_mapping", /* 18 */
82 "spell_turn_undead", /* 19 */
83 "spell_fear", /* 20 */
84 "spell_poison_cloud", /* 21 */
85 "spell_wonder", /* 22 */
86 "spell_destruction", /* 23 */
87 "spell_perceive_self", /* 24 */
88 "spell_word_of_recall", /* 25 */
89 "spell_invisible", /* 26 */
90 "spell_invisible_to_undead", /* 27 */
91 "spell_probe", /* 28 */
92 "spell_lg_magic_bullet", /* 29 */
93 "spell_improved_invisibility", /* 30 */
94 "spell_holy_word", /* 31 */
95 "spell_minor_healing", /* 32 */
96 "spell_medium_healing", /* 33 */
97 "spell_major_healing", /* 34 */
98 "spell_heal", /* 35 */
99 "spell_create_food", /* 36 */
100 "spell_earth_to_dust", /* 37 */
101 "spell_armour", /* 38 */
102 "spell_strength", /* 39 */
103 "spell_dexterity", /* 40 */
104 "spell_constitution", /* 41 */
105 "spell_charisma", /* 42 */
106 "spell_create_fire_wall", /* 43 */
107 "spell_create_frost_wall", /* 44 */
108 "spell_protection_from_cold", /* 45 */
109 "spell_protection_from_electricity", /* 46 */
110 "spell_protection_from_fire", /* 47 */
111 "spell_protection_from_poison", /* 48 */
112 "spell_protection_from_slow", /* 49 */
113 "spell_protection_from_paralysis", /* 50 */
114 "spell_protection_from_draining", /* 51 */
115 "spell_protection_from_magic", /* 52 */
116 "spell_protection_from_attack", /* 53 */
117 "spell_levitate", /* 54 */
118 "spell_small_speedball", /* 55 */
119 "spell_large_speedball", /* 56 */
120 "spell_hellfire", /* 57 */
121 "spell_dragonbreath", /* 58 */
122 "spell_large_icestorm", /* 59 */
123 "spell_charging", /* 60 */
124 "spell_polymorph", /* 61 */
125 "spell_cancellation", /* 62 */
126 "spell_confusion", /* 63 */
127 "spell_mass_confusion", /* 64 */
128 "spell_summon_pet_monster", /* 65 */
129 "spell_slow", /* 66 */
130 "spell_regenerate_spellpoints", /* 67 */
131 "spell_cure_poison", /* 68 */
132 "spell_protection_from_confusion", /* 69 */
133 "spell_protection_from_cancellation", /* 70 */
134 "spell_protection_from_depletion", /* 71 */
135 "spell_alchemy", /* 72 */
136 "spell_remove_curse", /* 73 */
137 "spell_remove_damnation", /* 74 */
138 "spell_identify", /* 75*/
139 "spell_detect_magic", /* 76 */
140 "spell_detect_monster", /* 77 */
141 "spell_detect_evil", /* 78 */
142 "spell_detect_curse", /* 79 */
143 "spell_heroism", /* 80 */
144 "spell_aggravation", /* 81 */
145 "spell_firebolt", /* 82 */
146 "spell_frostbolt", /* 83 */
147 "spell_shockwave", /* 84 */
148 "spell_color_spray", /* 85 */
149 "spell_haste", /* 86 */
150 "spell_face_of_death", /* 87 */
151 "spell_ball_lightning", /* 88 */
152 "spell_meteor_swarm", /* 89 */
153 "spell_comet", /* 90 */
154 "spell_mystic_fist", /* 91 */
155 "spell_raise_dead", /* 92 */
156 "spell_resurrection", /* 93 */
157 "spell_reincarnation", /* 94 */
158 "spell_immunity_to_cold", /* 95 */
159 "spell_immunity_to_electricity",/* 96 */
160 "spell_immunity_to_fire", /* 97 */
161 "spell_immunity_to_poison", /* 98 */
162 "spell_immunity_to_slow", /* 99 */
163 "spell_immunity_to_paralysis", /* 100 */
164 "spell_immunity_to_draining", /* 101 */
165 "spell_immunity_to_magic", /* 102 */
166 "spell_immunity_to_attack", /* 103 */
167 "spell_invulnerability", /* 104 */
168 "spell_defense", /* 105 */
169 "spell_rune_of_fire", /* 106 */
170 "spell_rune_of_frost", /* 107 */
171 "spell_rune_of_shocking", /* 108 */
172 "spell_rune_of_blasting", /* 109 */
173 "spell_rune_of_death", /* 110 */
174 "spell_marking_rune", /* 111 */
175 "spell_build_director", /* 112 */
176 "spell_create_pool_of_chaos", /* 113 */
177 "spell_build_bullet_wall", /* 114 */
178 "spell_build_lightning_wall", /* 115 */
179 "spell_build_fireball_wall", /* 116 */
180 "spell_magic_rune", /* 117 */
181 "spell_rune_of_magic_drain", /* 118 */
182 "spell_antimagic_rune", /* 119 */
183 "spell_rune_of_transference", /* 120 */
184 "spell_transference", /* 121 */
185 "spell_magic_drain", /* 122 */
186 "spell_counterspell", /* 123 */
187 "spell_disarm", /* 124 */
188 "spell_cure_confusion", /* 125 */
189 "spell_restoration", /* 126 */
190 "was summon evil monster", /* 127 */ /* Not implenented as nothing used it */
191 "spell_counterwall", /* 128 */
192 "spell_cause_light_wounds", /* 129 */
193 "spell_cause_medium_wounds", /* 130 */
194 "spell_cause_heavy_wounds", /* 131 */
195 "spell_charm_monsters", /* 132 */
196 "spell_banishment", /* 133 */
197 "spell_create_missile", /* 134 */
198 "spell_show_invisible", /* 135 */
199 "spell_xray", /* 136 */
200 "spell_pacify", /* 137 */
201 "spell_summon_fog", /* 138 */
202 "spell_steambolt", /* 139 */
203 "spell_command_undead", /* 140 */
204 "spell_holy_orb", /* 141 */
205 "spell_summon_avatar", /* 142 */
206 "spell_holy_possession", /* 143 */
207 "spell_bless", /* 144 */
208 "spell_curse", /* 145 */
209 "spell_regeneration", /* 146 */
210 "spell_consecrate", /* 147 */
211 "spell_summon_cult_monsters", /* 148 */
212 "spell_cause_critical_wounds", /* 149 */
213 "spell_holy_wrath", /* 150 */
214 "spell_retributive_strike", /* 151 */
215 "spell_finger_of_death", /* 152 */
216 "spell_insect_plague", /* 153 */
217 "spell_call_holy_servant", /* 154 */
218 "spell_wall_of_thorns", /* 155 */
219 "spell_staff_to_snake", /* 156 */
220 "spell_light", /* 157 */
221 "spell_darkness", /* 158 */
222 "spell_nightfall", /* 159 */
223 "spell_daylight", /* 160 */
224 "spell_sunspear", /* 161 */
225 "spell_faery_fire", /* 162 */
226 "spell_cure_blindness", /* 163 */
227 "spell_dark_vision", /* 164 */
228 "spell_bullet_swarm", /* 165 */
229 "spell_bullet_storm", /* 166 */
230 "spell_cause_many_wounds", /* 167 */
231 "spell_small_snowstorm", /* 168 */
232 "spell_medium_snowstorm", /* 169 */
233 "spell_large_snowstorm", /* 170 */
234 "spell_cure_disease", /* 171 */
235 "spell_cause_red_death", /* 172 */
236 "spell_cause_flu", /* 173 */
237 "spell_cause_black_death", /* 174 */
238 "spell_cause_leprosy", /* 175 */
239 "spell_cause_smallpox", /* 176 */
240 "spell_cause_white_death", /* 177 */
241 "spell_cause_anthrax", /* 178 */
242 "spell_cause_typhoid", /* 179 */
243 "spell_mana_blast", /* 180 */
244 "spell_small_manaball", /* 181 */
245 "spell_medium_manaball", /* 182 */
246 "spell_large_manaball", /* 183 */
247 "spell_manabolt", /* 184 */
248 "spell_dancing_sword", /* 185 */
249 "spell_animate_weapon", /* 186 */
250 "spell_cause_cold", /* 187 */
251 "spell_divine_shock", /* 188 */
252 "spell_windstorm", /* 189 */
253 "spell_sanctuary", /* 190 */
254 "spell_peace", /* 191 */
255 "spell_spiderweb", /* 192 */
256 "spell_conflict", /* 193 */
257 "spell_rage", /* 194 */
258 "spell_forked_lightning", /* 195 */
259 "spell_poison_fog", /* 196 */
260 "spell_flaming_aura", /* 197 */
261 "spell_vitriol", /* 198 */
262 "spell_vitriol_splash", /* 199 */
263 "spell_iron_skin", /* 200 */
264 "spell_wrathful_eye", /* 201 */
265 "spell_town_portal", /* 202 */
266 "spell_missile_swarm", /* 203 */
267 "spell_cause_rabies", /* 204 */
268 "spell_glyph", /* 205 */
269 NULL
270 };
271
272 #define SET_OR_CLEAR_FLAG(op, flag, val) \
273 { if (val) SET_FLAG(op, flag); else CLEAR_FLAG(op, flag); }
274
275 /* SET_RESIST is really only really needed for transition code. We normally
276 * don't care about multiple values overwriting each other, but this is
277 * to catch items that have multiple protection/immune/vulnerable.
278 * This can be simplified later on to just do the set after all the archs
279 * and maps have been updated.
280 * We always keep the last value because otherwise the value from the
281 * arch may take precedence.
282 * Unfortunately, we will report warnings here simply because an object has
283 * been modified from the arch.
284 */
285 #if 0 /* #if's don't work in #define macros */
286 #define SET_RESIST(op, type, val) \
287 {if (op->resist[type]!=0) { \
288 LOG(llevInfo, "object %s having multiple resistances set, type=%s, old=%d, new=%d\n", \
289 op->name?op->name:(op->arch?op->arch->name:"unknown"), \
290 resist_plus[type], op->resist[type], val); \
291 } op->resist[type] = val; }
292 #else
293 #define SET_RESIST(op, type, val) op->resist[type] = val;
294 #endif
295
296 #define IVAL atoi(yval())
297 #define FVAL atof(yval())
298 extern int arch_init;
299
300 /* Put this here since it is used below */
301 static void set_protection(object *op, uint32 mask, uint16 pro_val)
302 {
303 int i;
304
305 if (!mask) return; /* Unlikely, but might as well check */
306 for (i=0; i<NROFATTACKS; i++) {
307 if (mask & (1<<i)) SET_RESIST(op, i, pro_val);
308 }
309 }
310
311
312 static void set_body_info(object *op, char *params) {
313 int i;
314 char *cp;
315
316 /* go to first space character */
317 for (cp=params; !isspace(*cp); cp++) ;
318
319 *cp++ = 0; /* null it out */
320
321 for (i=0; i<NUM_BODY_LOCATIONS; i++) {
322 if (!strcmp(params, body_locations[i].save_name)) {
323 op->body_info[i] = atoi(cp);
324 return; /* Only one line passed in params */
325 }
326 }
327 LOG(llevError,"set_body_info called with bogus params: %s\n", params);
328 }
329
330 // return a suitable strign describign an objetc in enough detail to find it
331 // used only in check_loaded_object: TODO remove static, move it elsewhere and
332 // use it in more log messages.
333 static char *op_debug_info_ (object *op, char *info)
334 {
335 char info2[256 * 3];
336 char *p = info;
337
338 p += snprintf (p, 256, "%d=\"%s%s%s\"",
339 op->count,
340 op->name ? op->name : "(anon)",
341 op->title ? " " : "",
342 op->title ? op->title : "");
343
344 if (op->env)
345 p += snprintf (p, 256, "(in %s)", op_debug_info_ (op->env, info2));
346
347 if (op->map)
348 p += snprintf (p, 256, "(on %s@%d+%d)", op->map->path, op->x, op->y);
349
350 return info;
351 }
352
353 static char *op_debug_info (object *op)
354 {
355 static char info[256 * 3];
356
357 return op_debug_info_ (op, info);
358 }
359
360 /* This function checks the object after it has been loaded (when we
361 * get the 'end' in the input stream). This function can be used to
362 * deal with legacy objects where fields may have changed. It can also be used
363 * to check for objects to make sure there are no common errors.
364 */
365 static void check_loaded_object(object *op) {
366 int ip;
367
368 /* We do some specialized handling to handle legacy cases of name_pl.
369 * If the object doesn't have a name_pl, we just use the object name -
370 * this isn't perfect (things won't be properly pluralized), but works to
371 * that degree (5 heart is still quite understandable). But the case we
372 * also have to catch is if this object is not using the normal name for
373 * the object. In that case, we also want to use the loaded name.
374 * Otherwise, what happens is that the the plural name will lose
375 * information (appear as just 'hearts' and not 'goblins heart')
376 */
377 if (op->arch && op->name != op->arch->clone.name && op->name_pl == op->arch->clone.name_pl) {
378 if (op->name_pl) free_string(op->name_pl);
379 op->name_pl = NULL;
380 }
381 if (!op->name_pl) op->name_pl = add_string(op->name);
382
383 /* objects now have a materialname. try to patch it in */
384 if (!(IS_WEAPON(op) && op->level > 0)) {
385 if (op->map != NULL)
386 set_materialname(op, op->map->difficulty, NULL);
387 else
388 set_materialname(op, 5, NULL);
389 }
390 /* only do these when program is first run - a bit
391 * excessive to do this at every run - most of this is
392 * really just to catch any errors - program will still run, but
393 * not in the ideal fashion.
394 */
395 if ((op->type == WEAPON || op->type==BOW) && arch_init) {
396 if (!op->skill) {
397 LOG(llevError,"Weapon %s lacks a skill.\n", op_debug_info (op));
398 } else if ((!strcmp(op->skill,"one handed weapons") && op->body_info[1] != -1) ||
399 (!strcmp(op->skill,"two handed weapons") && op->body_info[1] != -2)) {
400 LOG(llevError,"weapon %s arm usage does not match skill: %d, %s\n",
401 op_debug_info (op), op->body_info[1], op->skill);
402 }
403 }
404
405 /* We changed last_heal to gen_sp_armour, which is what it
406 * really does for many objects. Need to catch any in maps
407 * that may have an old value.
408 */
409 if ((op->type == WEAPON) ||
410 (op->type == ARMOUR) || (op->type == HELMET) ||
411 (op->type == SHIELD) || (op->type == RING) ||
412 (op->type == BOOTS) || (op->type == GLOVES) ||
413 (op->type == AMULET ) || (op->type == GIRDLE) ||
414 (op->type == BRACERS ) || (op->type == CLOAK)) {
415 if (op->last_heal) {
416 LOG(llevDebug,"Object %s still has last_heal set, not gen_sp_armour\n", op_debug_info (op));
417 op->gen_sp_armour = op->last_heal;
418 op->last_heal = 0;
419 }
420 if (editor) ip =0;
421 else ip = calc_item_power(op, 0);
422 /* Legacy objects from before item power was in the game */
423 if (!op->item_power && ip) {
424 if (ip > 3) {
425 LOG(llevDebug,"Object %s had no item power, using %d\n", op_debug_info (op), ip);
426 }
427 op->item_power = ip;
428 }
429 /* Check for possibly bogus values. Has to meet both these criteria -
430 * something that has item_power 1 is probably just fine if our calculated
431 * value is 1 or 2 - these values are small enough that hard to be precise.
432 * similarly, it item_power is 0, the first check will always pass,
433 * but not the second one.
434 */
435 if (ip > 2 *op->item_power && ip > (op->item_power + 3)) {
436 LOG(llevDebug,"Object %s seems to have too low item power? %d > %d\n",
437 op_debug_info (op), ip, op->item_power);
438 }
439
440 }
441 /* Old spellcasting object - need to load in the appropiate object */
442 if ((op->type == ROD || op->type == WAND || op->type == SCROLL || op->type == HORN
443 || op->type == FIREWALL ||
444 /* POTIONS and ALTARS don't always cast spells, but if they do, update them */
445 ((op->type == POTION || op->type == ALTAR) && op->stats.sp)) && !op->inv && !arch_init) {
446 object *tmp;
447
448 /* Fireall is bizarre in that spell type was stored in dam. Rest are 'normal'
449 * in that spell was stored in sp.
450 */
451 tmp = get_archetype(spell_mapping[op->type == FIREWALL?op->stats.dam:op->stats.sp]);
452 insert_ob_in_ob(tmp, op);
453 op->randomitems = NULL; /* So another spell isn't created for this object */
454 }
455 /* spellbooks & runes use slaying. But not to arch name, but to spell name */
456
457 if ((op->type == SPELLBOOK || op->type == RUNE) && op->slaying && !op->inv && !arch_init) {
458 object *tmp;
459
460 tmp = get_archetype_by_object_name(op->slaying);
461 insert_ob_in_ob(tmp, op);
462 op->randomitems = NULL; /* So another spell isn't created for this object */
463 /* without this, value is all screwed up */
464 op->value = op->arch->clone.value * op->inv->value;
465 }
466
467 if (QUERY_FLAG(op, FLAG_MONSTER)) {
468 if (op->stats.hp > op->stats.maxhp)
469 LOG(llevDebug,"Monster %s has hp set higher than maxhp (%d>%d)\n",
470 op_debug_info (op),
471 op->stats.hp, op->stats.maxhp);
472
473 /* The archs just need to be updated for this */
474 if (op->move_type ==0) op->move_type = MOVE_WALK;
475 }
476 if ((QUERY_FLAG(op,FLAG_GENERATOR) && QUERY_FLAG(op,FLAG_CONTENT_ON_GEN))
477 || op->type == CREATOR
478 || op->type == CONVERTER) {
479 /* Object will duplicate it's content as part of the
480 * generation process. To do this, we must flag inventory
481 * so it remains unevaluated concerning the randomitems and
482 * the living (a demonlord shouldn't cast from inside generator!)
483 */
484 flag_inv(op,FLAG_IS_A_TEMPLATE);
485 }
486
487 /* Handle player movers. We use move_type for player movers
488 * because they operate on their own time (move_on
489 * would potentially cause them to be triggered when someone steps
490 * on them). If move_type is set, presume person knows what they
491 * are doing, otherwise, set move_type based on maxhp value.
492 */
493 if (op->type == PLAYERMOVER) {
494 if (!op->move_type) {
495 if (op->stats.maxhp) {
496 op->move_type = MOVE_ALL;
497 op->stats.maxhp=0;
498 } else {
499 op->move_type = MOVE_WALK;
500 }
501 }
502 }
503
504 }
505
506 /* This extracts the key/value from the yytext field -
507 * calls set_ob_key_value() to actually set the value.
508 * Function basically has to find spaces, strip out extra,
509 * etc. strchr doesn't work as good because could also
510 * be tabs.
511 */
512 static void add_key_value(object * op) {
513 char * key = NULL;
514 char * value = NULL;
515 char * cp;
516 char * end;
517
518 /* First, skip over leading whitespace. */
519 for (cp = yytext; isspace(*cp); cp++) { ; }
520
521 key = cp;
522
523 /* Now look for the end of the key/field name. */
524 for (; !isspace(*cp); cp++) {
525 if (*cp == '\0') {
526 /* Oops, ran out of string! Set the key with an empty value. */
527 set_ob_key_value(op, key, NULL, TRUE);
528 return;
529 }
530 }
531
532 if (*cp == '\0') {
533 set_ob_key_value(op, key, NULL, TRUE);
534 return;
535 }
536
537 /* Chop off the key, and start at the next character. */
538 *cp = '\0';
539 cp++;
540 if (*cp == '\0') {
541 /* Was followed by one space? */
542 set_ob_key_value(op, key, NULL, TRUE);
543 return;
544 }
545
546 /* Now looking for the value. Skip over whitespace. */
547 for (; isspace(*cp); cp++) {
548 if (*cp == '\0') {
549 /* Guess not. */
550 set_ob_key_value(op, key, NULL, TRUE);
551 return;
552 }
553 }
554
555 value = cp;
556
557 /* Got last character before null and strip
558 * off tailing whitespace
559 */
560 for (end = value + (strlen(cp)-1); isspace(*end); end--) {
561 if (end == value) {
562 /* *blink blink* Still no value? */
563 set_ob_key_value(op, key, NULL, TRUE);
564 return;
565 }
566 *end='\0';
567 }
568 set_ob_key_value(op, key, value, TRUE);
569 }
570
571 static void set_move(MoveType *mt, char *params) {
572 char *str;
573 int i, negate;
574
575 if (isdigit(*params)) {
576 *mt = atoi(params);
577 } else {
578 *mt=0;
579 for (str=strtok(params, " "); str; str=strtok(NULL, " ")) {
580 negate=0;
581 if (!strcasecmp(str, "all"))
582 *mt |= MOVE_ALL;
583 else {
584 if (*str=='-') {
585 negate = 1;
586 str++;
587 }
588 for (i=0; move_name[i] != NULL; i++) {
589 if (!strcasecmp(move_name[i], str)) {
590 if (negate) {
591 *mt &= ~(1<<i);
592 } else {
593 *mt |= (1<<i);
594 }
595 break;
596 }
597 }
598 if (move_name[i] == NULL) {
599 /* fly is a special case - covers both fly_low and
600 * fly_high - since it doesn't match to a specific
601 * single bit, have to special case it.
602 */
603 if (!strcasecmp(str,"flying")) {
604 if (negate) {
605 *mt &= ~MOVE_FLYING;
606 } else {
607 *mt |= MOVE_FLYING;
608 }
609 } else {
610 LOG(llevDebug, "common/loader.l: set_move - unknown move string '%s'\n", str);
611 }
612 }
613 } /* Else not all move types */
614 } /* for strtok */
615 } /* Else not a numeric value */
616 }
617
618 %}
619
620
621
622 S [ \t]+.+
623 WS [ \t]*
624 A .+
625
626 %x MESSAGE
627 %x LORE
628 %x SCRIPT
629
630 /* Don't have to link with -lfl with this */
631 %option noyywrap
632
633 /* need yy_push_state, yy_pop_state */
634 %option stack
635
636 %%
637
638 %{
639 /* Declare some local variables */
640 int ismore=0;
641
642 lex_error=0;
643
644 %}
645
646 ^msg{WS}$ { BEGIN( MESSAGE ); msgbuf[0]='\0'; }
647 <MESSAGE>^endmsg{WS}$ { BEGIN( INITIAL );
648 /* Just print a warning so we can be reasonably safe
649 * about not overflowing the buffer.
650 */
651 if (strlen(msgbuf) >= HUGE_BUF)
652 {
653 LOG(llevDebug, "\n\tError message length >= %d: %d\n>%.80s<\n",
654 HUGE_BUF, strlen(op->msg),op->msg);
655 op->msg = add_string ("ERROR, please report: string too long, winged.\n");
656 }
657 else
658 op->msg = add_string (msgbuf);
659 }
660 <MESSAGE>.* {strcat(msgbuf, yytext); strcat(msgbuf,"\n"); }
661
662 ^lore{WS}$ { BEGIN( LORE ); lorebuf[0]='\0'; }
663 <LORE>^endlore{WS}$ { BEGIN( INITIAL );
664 op->lore=add_string(lorebuf);
665 /* Just print a warning so we can be reasonably safe
666 * about not overflowing the buffer.
667 */
668 if (strlen(op->lore) > (HUGE_BUF/2))
669 LOG(llevDebug, "\n\tWarning lore length > %d (max allowed=%d): %d\n>%.80s<\n",
670 HUGE_BUF/2, HUGE_BUF, strlen(op->lore),op->lore);
671 }
672 <LORE>.* {strcat(lorebuf, yytext); strcat(lorebuf,"\n"); }
673
674 ^object{S} { char *yv=yval();
675
676 if (*yv=='\0') {
677 LOG(llevError,"Object lacks name.\n");
678 return LL_IGNORED;
679 }
680 if (!arch_init) {
681 LOG(llevError,"Got object info when not in arch_init (%s)?\n", yv);
682 } else {
683 if (op->arch!=NULL) op->arch->name=add_string(yv);
684 op->name = add_string(yv);
685 }
686 }
687
688 ^name{S} { char *yv=yval();
689
690 if (*yv=='\0') LOG(llevError,"Name without val\n");
691 else FREE_AND_COPY(op->name, yv);
692 }
693 ^name_pl{S} { char *yv=yval();
694
695 if (*yv=='\0') LOG(llevError,"Name without val\n");
696 else FREE_AND_COPY(op->name_pl, yv);
697 }
698 ^attach{S} { char *yv=yval();
699 if (*yv)
700 op->attach = add_string (yv);
701 }
702 ^skill{S} FREE_AND_COPY(op->skill,yval());
703 ^custom_name{S} { char *yv=yval();
704
705 if (*yv=='\0') LOG(llevError,"Custom name without val\n");
706 else FREE_AND_COPY(op->custom_name, yv);
707 }
708 ^race{S} FREE_AND_COPY(op->race,yval());
709 ^slaying{S} FREE_AND_COPY(op->slaying, yval());
710 ^inventory.*$ LOG(llevError,"Got depreciated Inventory command?\n");
711
712
713 ^arch{S} { /* If op->arch has been set, then this new object
714 * must be part of the inventory. So process
715 * appropriately.
716 */
717 if (op->arch) {
718 object *tmp;
719 char *yv=yval();
720
721 tmp=get_object();
722 tmp->arch = find_archetype(yv);
723 if (tmp->arch!=NULL)
724 copy_object(&tmp->arch->clone,tmp);
725 else {
726 if (tmp->name) free_string(tmp->name);
727 /* record the name of the broken object */
728 tmp->name = add_string(yv);
729 }
730 strcpy(msgbuf, "");
731 strcpy(lorebuf, "");
732 lex_load(tmp, map_flags);
733 if (tmp->arch) {
734 insert_ob_in_ob(tmp,op);
735 }
736 else {
737 LOG(llevDebug,"Discarding object without arch: %s\n", tmp->name?tmp->name:"(null)");
738 free_object(tmp);
739 }
740 }
741 /* This is the actual archetype definition then */
742 else {
743 char *yv=yval();
744
745 op->arch=find_archetype(yv);
746 if (op->arch!=NULL) copy_object(&op->arch->clone,op);
747 else if (!arch_init) {
748 if (op->name) free_string(op->name);
749 /* record the name of the broken object */
750 op->name = add_string(yv);
751 }
752 }
753 }
754
755 ^other_arch{S} op->other_arch=find_archetype(yval());
756 ^animation{S} {
757 if (strcmp (yval(), "NONE") == 0) {
758 op->animation_id = 0;
759 CLEAR_FLAG (op, FLAG_ANIMATE);
760 } else {
761 op->animation_id = find_animation (yval());
762 SET_FLAG (op, FLAG_ANIMATE);
763 }
764 }
765
766 ^more{WS}$ { /* We need to record that this is a multipart object,
767 * so the calling function can glue things back together
768 */
769 ismore=1;
770 }
771
772 ^end{WS}$ { check_loaded_object(op);
773 if (ismore) return LL_MORE;
774 else return LL_NORMAL;
775 }
776 ^last_heal{S} op->last_heal = IVAL;
777 ^last_sp{S} op->last_sp = IVAL;
778 ^last_grace{S} op->last_grace = IVAL;
779 ^last_eat{S} op->last_eat = IVAL;
780 ^speed{S} { op->speed = FVAL;
781 if (!(map_flags & MAP_STYLE)) {
782 if (op->speed<0) op->speed_left = op->speed_left-RANDOM()%100/100.0;
783 update_ob_speed(op);
784 }
785 }
786 ^speed_left{S} op->speed_left = FVAL;
787 ^slow_move{S} { op->move_slow |= MOVE_WALK;
788 op->move_slow_penalty = FVAL;
789 }
790 ^title{S} { char *y=yval();
791 if (*y=='\0') LOG(llevError,"Title without value.\n");
792 else FREE_AND_COPY(op->title, y);
793 }
794
795 ^face{S} op->face = &new_faces[FindFace(yval(), 0)];
796 ^str{S} op->stats.Str = IVAL;
797 ^dex{S} op->stats.Dex = IVAL;
798 ^con{S} op->stats.Con = IVAL;
799 ^wis{S} op->stats.Wis = IVAL;
800 ^cha{S} op->stats.Cha = IVAL;
801 ^int{S} op->stats.Int = IVAL;
802 ^pow{S} op->stats.Pow = IVAL;
803 ^hp{S} op->stats.hp = IVAL;
804 ^maxhp{S} op->stats.maxhp = IVAL;
805 ^sp{S} op->stats.sp = IVAL;
806 ^maxsp{S} op->stats.maxsp = IVAL;
807 ^grace{S} op->stats.grace = IVAL;
808 ^maxgrace{S} op->stats.maxgrace = IVAL;
809 ^exp{S} op->stats.exp = atoll(yval());
810 ^perm_exp{S} op->perm_exp = atoll(yval());
811 ^food{S} op->stats.food = IVAL;
812 ^dam{S} op->stats.dam = IVAL;
813 ^wc{S} op->stats.wc = IVAL;
814 ^ac{S} op->stats.ac = IVAL;
815 ^x{S} {op->x = IVAL; op->ox= op->x; }
816 ^y{S} {op->y = IVAL; op->oy= op->y; }
817 ^nrof{S} op->nrof= atol(yval());
818 ^level{S} op->level = IVAL;
819 ^direction{S} op->direction = IVAL;
820 ^type{S} op->type = IVAL;
821 ^subtype{S} op->subtype = IVAL;
822 ^material{S} op->material = IVAL;
823 ^materialname{S} { char *yv=yval();
824 if (*yv=='\0')
825 LOG(llevError,"Materialname without val\n");
826 else
827 FREE_AND_COPY(op->materialname, yv);
828 }
829
830 ^value{S} op->value = IVAL;
831 ^weight{S} op->weight = atol(yval());
832 ^carrying{S} op->carrying = atol(yval());
833 ^attacktype{S} op->attacktype = IVAL;
834 ^path_attuned{S} op->path_attuned = IVAL;
835 ^path_repelled{S} op->path_repelled = IVAL;
836 ^path_denied{S} op->path_denied = IVAL;
837 ^invisible{S} op->invisible = IVAL;
838 ^magic{S} op->magic = IVAL;
839 ^state{S} op->state = IVAL;
840 ^alive{S} SET_OR_CLEAR_FLAG(op, FLAG_ALIVE, IVAL);
841 ^applied{S} SET_OR_CLEAR_FLAG(op, FLAG_APPLIED, IVAL);
842 ^unpaid{S} SET_OR_CLEAR_FLAG(op, FLAG_UNPAID, IVAL);
843 ^need_an{S} { /* not used - just ignore */ }
844 ^need_ie{S} { /* not used - jsut ignore */ }
845 ^is_animated{S} SET_OR_CLEAR_FLAG(op, FLAG_ANIMATE, IVAL);
846 ^no_pick{S} SET_OR_CLEAR_FLAG(op, FLAG_NO_PICK, IVAL);
847
848 %{ /* These are all legacy - any new objects should use the move_ .. values */
849 %}
850 ^no_pass{S} { if (IVAL) op->move_block = MOVE_ALL; else op->move_block=0; }
851 ^walk_on{S} { if (IVAL) op->move_on |= MOVE_WALK; else op->move_on &= ~MOVE_WALK; }
852 ^walk_off{S} { if (IVAL) op->move_off |= MOVE_WALK; else op->move_off &= ~MOVE_WALK; }
853 ^fly_on{S} { if (IVAL) op->move_on |= MOVE_FLY_LOW; else op->move_on &= ~MOVE_FLY_LOW; }
854 ^fly_off{S} { if (IVAL) op->move_off |= MOVE_FLY_LOW; else op->move_off &= ~MOVE_FLY_LOW; }
855 ^flying{S} { if (IVAL) op->move_type |= MOVE_FLY_LOW; else op->move_type &= ~MOVE_FLY_LOW; }
856
857 %{ /* These are the new values */
858 %}
859 ^move_block{S} set_move(&op->move_block, yval());
860 ^move_allow{S} set_move(&op->move_allow, yval());
861 ^move_type{S} set_move(&op->move_type, yval());
862 ^move_on{S} set_move(&op->move_on, yval());
863 ^move_off{S} set_move(&op->move_off, yval());
864 ^move_slow{S} set_move(&op->move_slow, yval());
865 ^move_slow_penalty{S} op->move_slow_penalty = FVAL;
866
867
868 ^monster{S} SET_OR_CLEAR_FLAG(op, FLAG_MONSTER, IVAL);
869 ^neutral{S} SET_OR_CLEAR_FLAG(op, FLAG_NEUTRAL, IVAL);
870 ^no_attack{S} SET_OR_CLEAR_FLAG(op, FLAG_NO_ATTACK, IVAL);
871 ^no_damage{S} SET_OR_CLEAR_FLAG(op, FLAG_NO_DAMAGE, IVAL);
872 ^friendly{S} { if (IVAL) {
873 SET_FLAG(op, FLAG_FRIENDLY);
874 if (op->type != PLAYER)
875 add_friendly_object (op);
876 }
877 else CLEAR_FLAG(op, FLAG_FRIENDLY);
878 }
879 ^generator{S} SET_OR_CLEAR_FLAG(op, FLAG_GENERATOR, IVAL);
880 ^use_content_on_gen{S} SET_OR_CLEAR_FLAG (op,FLAG_CONTENT_ON_GEN, IVAL);
881 ^is_thrown{S} SET_OR_CLEAR_FLAG(op, FLAG_IS_THROWN, IVAL);
882 ^auto_apply{S} SET_OR_CLEAR_FLAG(op, FLAG_AUTO_APPLY, IVAL);
883 ^treasure{S} SET_OR_CLEAR_FLAG(op, FLAG_TREASURE, IVAL);
884 ^see_invisible{S} SET_OR_CLEAR_FLAG(op, FLAG_SEE_INVISIBLE, IVAL);
885 ^can_roll{S} SET_OR_CLEAR_FLAG(op, FLAG_CAN_ROLL, IVAL);
886 ^overlay_floor{S} SET_OR_CLEAR_FLAG(op, FLAG_OVERLAY_FLOOR, IVAL);
887 ^is_turnable{S} SET_OR_CLEAR_FLAG(op, FLAG_IS_TURNABLE, IVAL);
888 ^is_used_up{S} SET_OR_CLEAR_FLAG(op, FLAG_IS_USED_UP, IVAL);
889 ^identified{S} { if (IVAL) {
890 SET_FLAG(op, FLAG_IDENTIFIED);
891 CLEAR_FLAG(op, FLAG_KNOWN_MAGICAL);
892 }
893 else CLEAR_FLAG(op, FLAG_IDENTIFIED);
894 }
895 ^reflecting{S} SET_OR_CLEAR_FLAG(op, FLAG_REFLECTING, IVAL);
896 ^changing{S} SET_OR_CLEAR_FLAG(op, FLAG_CHANGING, IVAL);
897 ^splitting{S} SET_OR_CLEAR_FLAG(op, FLAG_SPLITTING, IVAL);
898 ^hitback{S} SET_OR_CLEAR_FLAG(op, FLAG_HITBACK, IVAL);
899 ^startequip{S} SET_OR_CLEAR_FLAG(op, FLAG_STARTEQUIP, IVAL);
900 ^blocksview{S} SET_OR_CLEAR_FLAG(op, FLAG_BLOCKSVIEW, IVAL);
901 ^editable{S} op->arch->editable = IVAL;
902 ^editor_folder{S} { }
903 ^undead{S} SET_OR_CLEAR_FLAG(op, FLAG_UNDEAD, IVAL);
904 ^scared{S} SET_OR_CLEAR_FLAG(op, FLAG_SCARED, IVAL);
905 ^unaggressive{S} SET_OR_CLEAR_FLAG(op, FLAG_UNAGGRESSIVE, IVAL);
906 ^reflect_missile{S} SET_OR_CLEAR_FLAG(op, FLAG_REFL_MISSILE, IVAL);
907 ^reflect_spell{S} SET_OR_CLEAR_FLAG(op, FLAG_REFL_SPELL, IVAL);
908 ^no_magic{S} SET_OR_CLEAR_FLAG(op, FLAG_NO_MAGIC, IVAL);
909 ^wiz{S} { if (IVAL) {
910 SET_FLAG(op, FLAG_WIZ);
911 SET_FLAG(op, FLAG_WAS_WIZ);
912 SET_FLAG(op, FLAG_WIZPASS);
913 SET_FLAG(op, FLAG_WIZCAST);
914 }
915 else {
916 CLEAR_FLAG(op, FLAG_WIZ);
917 CLEAR_FLAG(op, FLAG_WIZPASS);
918 CLEAR_FLAG(op, FLAG_WIZCAST);
919 }
920 }
921 ^was_wiz{S} SET_OR_CLEAR_FLAG(op, FLAG_WAS_WIZ, IVAL);
922 ^no_fix_player{S} SET_OR_CLEAR_FLAG(op, FLAG_NO_FIX_PLAYER, IVAL);
923 ^is_lightable{S} SET_OR_CLEAR_FLAG(op, FLAG_IS_LIGHTABLE, IVAL);
924 ^tear_down{S} SET_OR_CLEAR_FLAG(op, FLAG_TEAR_DOWN, IVAL);
925 ^luck{S} op->stats.luck = IVAL;
926 ^run_away{S} op->run_away = IVAL;
927 ^pick_up{S} op->pick_up = IVAL;
928 ^item_power{S} op->item_power = IVAL;
929 ^gen_sp_armour{S} op->gen_sp_armour = IVAL;
930 ^anim_speed{S} op->anim_speed = IVAL;
931 ^container{S} op->weight_limit = IVAL;
932 ^no_drop{S} SET_OR_CLEAR_FLAG(op, FLAG_NO_DROP, IVAL);
933 ^will_apply{S} op->will_apply = IVAL;
934 ^random_movement{S} SET_OR_CLEAR_FLAG(op, FLAG_RANDOM_MOVE, IVAL);
935 ^can_apply{S} { }
936 ^can_use_shield{S} SET_OR_CLEAR_FLAG(op, FLAG_USE_SHIELD, IVAL);
937 ^can_cast_spell{S} SET_OR_CLEAR_FLAG(op, FLAG_CAST_SPELL, IVAL);
938 ^can_use_scroll{S} SET_OR_CLEAR_FLAG(op, FLAG_USE_SCROLL, IVAL);
939 ^can_use_range{S} SET_OR_CLEAR_FLAG(op, FLAG_USE_RANGE, IVAL);
940 ^can_use_bow{S} SET_OR_CLEAR_FLAG(op, FLAG_USE_BOW, IVAL);
941 ^can_use_armour{S} SET_OR_CLEAR_FLAG(op, FLAG_USE_ARMOUR, IVAL);
942 ^can_use_weapon{S} SET_OR_CLEAR_FLAG(op, FLAG_USE_WEAPON, IVAL);
943 ^can_use_ring{S} SET_OR_CLEAR_FLAG(op, FLAG_USE_RING, IVAL);
944 ^has_ready_bow{S} SET_OR_CLEAR_FLAG(op, FLAG_READY_BOW, IVAL);
945 ^xrays{S} SET_OR_CLEAR_FLAG(op, FLAG_XRAYS, IVAL);
946 ^is_floor{S} SET_OR_CLEAR_FLAG(op, FLAG_IS_FLOOR, IVAL);
947 ^lifesave{S} SET_OR_CLEAR_FLAG(op, FLAG_LIFESAVE, IVAL);
948 ^no_strength{S} SET_OR_CLEAR_FLAG(op, FLAG_NO_STRENGTH, IVAL);
949 ^sleep{S} {
950 SET_OR_CLEAR_FLAG(op, FLAG_SLEEP, IVAL);
951 /*(LOG(llevDebug," Warning: Object %s has sleep set in arch.\n",op->name);*/
952 }
953 ^stand_still{S} SET_OR_CLEAR_FLAG(op, FLAG_STAND_STILL, IVAL);
954 ^random_move{S} SET_OR_CLEAR_FLAG(op, FLAG_RANDOM_MOVE, IVAL);
955 ^only_attack{S} SET_OR_CLEAR_FLAG(op, FLAG_ONLY_ATTACK, IVAL);
956
957 ^activate_on_push{S} SET_OR_CLEAR_FLAG(op, FLAG_ACTIVATE_ON_PUSH, IVAL);
958 ^activate_on_release{S} SET_OR_CLEAR_FLAG(op, FLAG_ACTIVATE_ON_RELEASE, IVAL);
959
960 /* armour is loaded for compatiblity reasons */
961 ^armour{S} SET_RESIST(op, ATNR_PHYSICAL, IVAL);
962 /* Start of various attacktypes */
963 ^resist_physical{S} SET_RESIST(op, ATNR_PHYSICAL, IVAL);
964 ^resist_magic{S} SET_RESIST(op, ATNR_MAGIC, IVAL);
965 ^resist_fire{S} SET_RESIST(op, ATNR_FIRE, IVAL);
966 ^resist_electricity{S} SET_RESIST(op, ATNR_ELECTRICITY, IVAL);
967 ^resist_cold{S} SET_RESIST(op, ATNR_COLD, IVAL);
968 ^resist_confusion{S} SET_RESIST(op, ATNR_CONFUSION, IVAL);
969 ^resist_acid{S} SET_RESIST(op, ATNR_ACID, IVAL);
970 ^resist_drain{S} SET_RESIST(op, ATNR_DRAIN, IVAL);
971 ^resist_weaponmagic{S} SET_RESIST(op, ATNR_WEAPONMAGIC, IVAL);
972 ^resist_ghosthit{S} SET_RESIST(op, ATNR_GHOSTHIT, IVAL);
973 ^resist_poison{S} SET_RESIST(op, ATNR_POISON, IVAL);
974 ^resist_slow{S} SET_RESIST(op, ATNR_SLOW, IVAL);
975 ^resist_paralyze{S} SET_RESIST(op, ATNR_PARALYZE, IVAL);
976 ^resist_turn_undead{S} SET_RESIST(op, ATNR_TURN_UNDEAD, IVAL);
977 ^resist_fear{S} SET_RESIST(op, ATNR_FEAR, IVAL);
978 ^resist_cancellation{S} SET_RESIST(op, ATNR_CANCELLATION, IVAL);
979 ^resist_deplete{S} SET_RESIST(op, ATNR_DEPLETE, IVAL);
980 ^resist_death{S} SET_RESIST(op, ATNR_DEATH, IVAL);
981 ^resist_chaos{S} SET_RESIST(op, ATNR_CHAOS, IVAL);
982 ^resist_counterspell{S} SET_RESIST(op, ATNR_COUNTERSPELL, IVAL);
983 ^resist_godpower{S} SET_RESIST(op, ATNR_GODPOWER, IVAL);
984 ^resist_holyword{S} SET_RESIST(op, ATNR_HOLYWORD, IVAL);
985 ^resist_blind{S} SET_RESIST(op, ATNR_BLIND, IVAL);
986 ^resist_internal{S} SET_RESIST(op, ATNR_INTERNAL, IVAL);
987 ^resist_life_stealing{S} SET_RESIST(op, ATNR_LIFE_STEALING, IVAL);
988 ^resist_disease{S} SET_RESIST(op, ATNR_DISEASE, IVAL);
989
990 /* Old style resistances */
991 ^immune{S} set_protection(op, IVAL, RESIST_IMMUNE);
992 ^protected{S} set_protection(op, IVAL, RESIST_PROT);
993 ^vulnerable{S} set_protection(op, IVAL, (uint16) RESIST_VULN);
994
995 /* old values - keep them around for now, but they should be removed at some point */
996 ^has_ready_rod{S} SET_OR_CLEAR_FLAG(op, FLAG_READY_RANGE, IVAL);
997 ^has_ready_horn{S} SET_OR_CLEAR_FLAG(op, FLAG_READY_RANGE, IVAL);
998 ^has_ready_wand{S} SET_OR_CLEAR_FLAG(op, FLAG_READY_RANGE, IVAL);
999 ^can_use_wand{S} SET_OR_CLEAR_FLAG(op, FLAG_USE_RANGE, IVAL);
1000
1001 ^attack_movement{S} op->attack_movement = IVAL;
1002 ^move_state{S} op->move_status = IVAL;
1003 ^confused{S} SET_OR_CLEAR_FLAG(op, FLAG_CONFUSED, IVAL);
1004 ^stealth{S} SET_OR_CLEAR_FLAG(op, FLAG_STEALTH, IVAL);
1005 ^connected{S} add_button_link(op, op->map, IVAL);
1006 ^cursed{S} SET_OR_CLEAR_FLAG(op, FLAG_CURSED, IVAL);
1007 ^damned{S} SET_OR_CLEAR_FLAG(op, FLAG_DAMNED, IVAL);
1008 ^see_anywhere{S} SET_OR_CLEAR_FLAG(op, FLAG_SEE_ANYWHERE, IVAL);
1009 ^known_magical{S} SET_OR_CLEAR_FLAG(op, FLAG_KNOWN_MAGICAL, IVAL);
1010 ^known_cursed{S} SET_OR_CLEAR_FLAG(op, FLAG_KNOWN_CURSED, IVAL);
1011 ^can_use_skill{S} SET_OR_CLEAR_FLAG(op, FLAG_CAN_USE_SKILL, IVAL);
1012 ^been_applied{S} SET_OR_CLEAR_FLAG(op, FLAG_BEEN_APPLIED, IVAL);
1013 ^has_ready_scroll{S} SET_OR_CLEAR_FLAG(op, FLAG_READY_SCROLL, IVAL);
1014 ^can_use_rod{S} SET_OR_CLEAR_FLAG(op, FLAG_USE_ROD, IVAL);
1015 ^can_use_horn{S} SET_OR_CLEAR_FLAG(op, FLAG_USE_HORN, IVAL);
1016 ^expmul{S} op->expmul = FVAL;
1017 ^unique{S} SET_OR_CLEAR_FLAG(op, FLAG_UNIQUE, IVAL);
1018 ^make_invisible{S} SET_OR_CLEAR_FLAG(op, FLAG_MAKE_INVIS, IVAL);
1019 ^inv_locked{S} SET_OR_CLEAR_FLAG(op, FLAG_INV_LOCKED, IVAL);
1020 ^is_wooded{S} SET_OR_CLEAR_FLAG(op, FLAG_IS_WOODED, IVAL);
1021 ^is_hilly{S} SET_OR_CLEAR_FLAG(op, FLAG_IS_HILLY, IVAL);
1022 ^is_water{S} SET_OR_CLEAR_FLAG(op, FLAG_IS_WATER, IVAL);
1023 ^has_ready_skill{S} SET_OR_CLEAR_FLAG(op, FLAG_READY_SKILL, IVAL);
1024 ^has_ready_weapon{S} SET_OR_CLEAR_FLAG(op, FLAG_READY_WEAPON, IVAL);
1025 ^no_skill_ident{S} SET_OR_CLEAR_FLAG(op, FLAG_NO_SKILL_IDENT, IVAL);
1026 ^glow_radius{S} op->glow_radius = IVAL;
1027 ^is_blind{S} SET_OR_CLEAR_FLAG(op, FLAG_BLIND, IVAL);
1028 ^can_see_in_dark{S} SET_OR_CLEAR_FLAG(op, FLAG_SEE_IN_DARK, IVAL);
1029 ^is_cauldron{S} SET_OR_CLEAR_FLAG(op, FLAG_IS_CAULDRON, IVAL);
1030 ^randomitems{S} op->randomitems = find_treasurelist(yval());
1031 ^no_steal{S} SET_OR_CLEAR_FLAG(op, FLAG_NO_STEAL, IVAL);
1032 ^one_hit{S} SET_OR_CLEAR_FLAG(op, FLAG_ONE_HIT, IVAL);
1033 ^berserk{S} SET_OR_CLEAR_FLAG(op, FLAG_BERSERK, IVAL);
1034
1035 ^can_knockback{S} { /* Some archetypes have these values in them */ }
1036 ^can_parry{S} { /* Probably the pupland archetypes - I imagined */ }
1037 ^can_impale{S} { /* That these are for the new combat code */ }
1038 ^can_cut{S} { /* just ignore for now */ }
1039 ^can_dam_armour{S} { }
1040 ^weapontype{S} op->weapontype = IVAL;
1041 ^tooltype{S} op->tooltype = IVAL;
1042 ^casting_time{S} op->casting_time = (sint16) FVAL;
1043 ^elevation{S} op->elevation = IVAL;
1044 ^smoothlevel{S} op->smoothlevel = IVAL;
1045 ^client_type{S} op->client_type = IVAL;
1046 ^body_{A} set_body_info(op, yytext);
1047 ^duration{S} op->duration = IVAL;
1048 ^range{S} op->range = IVAL;
1049 ^range_modifier{S} op->range_modifier = IVAL;
1050 ^dam_modifier{S} op->dam_modifier = IVAL;
1051 ^duration_modifier{S} op->duration_modifier = IVAL;
1052 ^is_buildable{S} SET_OR_CLEAR_FLAG( op, FLAG_IS_BUILDABLE, IVAL );
1053
1054 ^event_apply{S} {
1055 char *yv=yval();
1056 if (*yv=='\0')
1057 LOG(llevError,"Event (apply) without val\n");
1058 else
1059 insert_event(op,EVENT_APPLY,yv,NULL,NULL);
1060 }
1061
1062 ^event_apply_plugin{S} {
1063 char *yv=yval();
1064 if (*yv=='\0')
1065 LOG(llevError,"Event (apply) without plugin\n");
1066 else
1067 insert_event(op,EVENT_APPLY,NULL,yv,NULL);
1068 }
1069
1070 ^event_apply_options{S} {
1071 char *yv=yval();
1072 if (*yv=='\0')
1073 LOG(llevError,"Event (apply) without options\n");
1074 else
1075 insert_event(op,EVENT_APPLY,NULL,NULL,yv);
1076 }
1077
1078 ^event_attack{S} {
1079 char *yv=yval();
1080 if (*yv=='\0')
1081 LOG(llevError,"Event (attack) without val\n");
1082 else
1083 insert_event(op,EVENT_ATTACK,yv,NULL,NULL);
1084 }
1085
1086 ^event_attack_plugin{S} {
1087 char *yv=yval();
1088 if (*yv=='\0')
1089 LOG(llevError,"Event (attack) without plugin\n");
1090 else
1091 insert_event(op,EVENT_ATTACK,NULL,yv,NULL);
1092 }
1093
1094 ^event_attack_options{S} {
1095 char *yv=yval();
1096 if (*yv=='\0')
1097 LOG(llevError,"Event (attack) without options\n");
1098 else
1099 insert_event(op,EVENT_ATTACK,NULL,NULL,yv);
1100 }
1101 ^event_death{S} {
1102 char *yv=yval();
1103 if (*yv=='\0')
1104 LOG(llevError,"Event (death) without val\n");
1105 else
1106 insert_event(op,EVENT_DEATH,yv,NULL,NULL);
1107 }
1108
1109 ^event_death_plugin{S} {
1110 char *yv=yval();
1111 if (*yv=='\0')
1112 LOG(llevError,"Event (death) without plugin\n");
1113 else
1114 insert_event(op,EVENT_DEATH,NULL,yv,NULL);
1115 }
1116
1117 ^event_death_options{S} {
1118 char *yv=yval();
1119 if (*yv=='\0')
1120 LOG(llevError,"Event (death) without options\n");
1121 else
1122 insert_event(op,EVENT_DEATH,NULL,NULL,yv);
1123 }
1124 ^event_drop{S} {
1125 char *yv=yval();
1126 if (*yv=='\0')
1127 LOG(llevError,"Event (drop) without val\n");
1128 else
1129 insert_event(op,EVENT_DROP,yv,NULL,NULL);
1130 }
1131
1132 ^event_drop_plugin{S} {
1133 char *yv=yval();
1134 if (*yv=='\0')
1135 LOG(llevError,"Event (drop) without plugin\n");
1136 else
1137 insert_event(op,EVENT_DROP,NULL,yv,NULL);
1138 }
1139
1140 ^event_drop_options{S} {
1141 char *yv=yval();
1142 if (*yv=='\0')
1143 LOG(llevError,"Event (drop) without options\n");
1144 else
1145 insert_event(op,EVENT_DROP,NULL,NULL,yv);
1146 }
1147 ^event_pickup{S} {
1148 char *yv=yval();
1149 if (*yv=='\0')
1150 LOG(llevError,"Event (pickup) without val\n");
1151 else
1152 insert_event(op,EVENT_PICKUP,yv,NULL,NULL);
1153 }
1154
1155 ^event_pickup_plugin{S} {
1156 char *yv=yval();
1157 if (*yv=='\0')
1158 LOG(llevError,"Event (pickup) without plugin\n");
1159 else
1160 insert_event(op,EVENT_PICKUP,NULL,yv,NULL);
1161 }
1162
1163 ^event_pickup_options{S} {
1164 char *yv=yval();
1165 if (*yv=='\0')
1166 LOG(llevError,"Event (pickup) without options\n");
1167 else
1168 insert_event(op,EVENT_PICKUP,NULL,NULL,yv);
1169 }
1170 ^event_say{S} {
1171 char *yv=yval();
1172 if (*yv=='\0')
1173 LOG(llevError,"Event (say) without val\n");
1174 else
1175 insert_event(op,EVENT_SAY,yv,NULL,NULL);
1176 }
1177
1178 ^event_say_plugin{S} {
1179 char *yv=yval();
1180 if (*yv=='\0')
1181 LOG(llevError,"Event (say) without plugin\n");
1182 else
1183 insert_event(op,EVENT_SAY,NULL,yv,NULL);
1184 }
1185
1186 ^event_say_options{S} {
1187 char *yv=yval();
1188 if (*yv=='\0')
1189 LOG(llevError,"Event (say) without options\n");
1190 else
1191 insert_event(op,EVENT_SAY,NULL,NULL,yv);
1192 }
1193 ^event_stop{S} {
1194 char *yv=yval();
1195 if (*yv=='\0')
1196 LOG(llevError,"Event (stop) without val\n");
1197 else
1198 insert_event(op,EVENT_STOP,yv,NULL,NULL);
1199 }
1200
1201 ^event_stop_plugin{S} {
1202 char *yv=yval();
1203 if (*yv=='\0')
1204 LOG(llevError,"Event (stop) without plugin\n");
1205 else
1206 insert_event(op,EVENT_STOP,NULL,yv,NULL);
1207 }
1208
1209 ^event_stop_options{S} {
1210 char *yv=yval();
1211 if (*yv=='\0')
1212 LOG(llevError,"Event (stop) without options\n");
1213 else
1214 insert_event(op,EVENT_STOP,NULL,NULL,yv);
1215 }
1216 ^event_time{S} {
1217 char *yv=yval();
1218 if (*yv=='\0')
1219 LOG(llevError,"Event (time) without val\n");
1220 else
1221 insert_event(op,EVENT_TIME,yv,NULL,NULL);
1222 }
1223
1224 ^event_time_plugin{S} {
1225 char *yv=yval();
1226 if (*yv=='\0')
1227 LOG(llevError,"Event (time) without plugin\n");
1228 else
1229 insert_event(op,EVENT_TIME,NULL,yv,NULL);
1230 }
1231
1232 ^event_time_options{S} {
1233 char *yv=yval();
1234 if (*yv=='\0')
1235 LOG(llevError,"Event (time) without options\n");
1236 else
1237 insert_event(op,EVENT_TIME,NULL,NULL,yv);
1238 }
1239 ^event_throw{S} {
1240 char *yv=yval();
1241 if (*yv=='\0')
1242 LOG(llevError,"Event (throw) without val\n");
1243 else
1244 insert_event(op,EVENT_THROW,yv,NULL,NULL);
1245 }
1246
1247 ^event_throw_plugin{S} {
1248 char *yv=yval();
1249 if (*yv=='\0')
1250 LOG(llevError,"Event (throw) without plugin\n");
1251 else
1252 insert_event(op,EVENT_THROW,NULL,yv,NULL);
1253 }
1254
1255 ^event_throw_options{S} {
1256 char *yv=yval();
1257 if (*yv=='\0')
1258 LOG(llevError,"Event (apply) without options\n");
1259 else
1260 insert_event(op,EVENT_THROW,NULL,NULL,yv);
1261 }
1262 ^event_trigger{S} {
1263 char *yv=yval();
1264 if (*yv=='\0')
1265 LOG(llevError,"Event (trigger) without val\n");
1266 else
1267 insert_event(op,EVENT_TRIGGER,yv,NULL,NULL);
1268 }
1269
1270 ^event_trigger_plugin{S} {
1271 char *yv=yval();
1272 if (*yv=='\0')
1273 LOG(llevError,"Event (trigger) without plugin\n");
1274 else
1275 insert_event(op,EVENT_TRIGGER,NULL,yv,NULL);
1276 }
1277
1278 ^event_trigger_options{S} {
1279 char *yv=yval();
1280 if (*yv=='\0')
1281 LOG(llevError,"Event (trigger) without options\n");
1282 else
1283 insert_event(op,EVENT_TRIGGER,NULL,NULL,yv);
1284 }
1285 ^event_close{S} {
1286 char *yv=yval();
1287 if (*yv=='\0')
1288 LOG(llevError,"Event (close) without val\n");
1289 else
1290 insert_event(op,EVENT_CLOSE,yv,NULL,NULL);
1291 }
1292
1293 ^event_close_plugin{S} {
1294 char *yv=yval();
1295 if (*yv=='\0')
1296 LOG(llevError,"Event (close) without plugin\n");
1297 else
1298 insert_event(op,EVENT_CLOSE,NULL,yv,NULL);
1299 }
1300
1301 ^event_close_options{S} {
1302 char *yv=yval();
1303 if (*yv=='\0')
1304 LOG(llevError,"Event (close) without options\n");
1305 else
1306 insert_event(op,EVENT_CLOSE,NULL,NULL,yv);
1307 }
1308 ^event_timer{S} {
1309 char *yv=yval();
1310 if (*yv=='\0')
1311 LOG(llevError,"Event (timer) without val\n");
1312 else
1313 insert_event(op,EVENT_TIMER,yv,NULL,NULL);
1314 }
1315
1316 ^event_timer_plugin{S} {
1317 char *yv=yval();
1318 if (*yv=='\0')
1319 LOG(llevError,"Event (timer) without plugin\n");
1320 else
1321 insert_event(op,EVENT_TIMER,NULL,yv,NULL);
1322 }
1323
1324 ^event_timer_options{S} {
1325 char *yv=yval();
1326 if (*yv=='\0')
1327 LOG(llevError,"Event (timer) without options\n");
1328 else
1329 insert_event(op,EVENT_TIMER,NULL,NULL,yv);
1330 }
1331
1332 ^current_weapon_script{S} { char *yv=yval();
1333
1334 if (*yv=='\0') LOG(llevError,"Script (current weapon) without val\n");
1335 else
1336 {
1337 FREE_AND_COPY(op->current_weapon_script, yv);
1338 };
1339 }
1340
1341 <*>(^{WS}$)|\n {/* ignore empty lines, newlines we don't do above */}
1342 #.*\n {}
1343
1344 <<EOF>> {/* If we got an error, return the error. Otherwise, return that we got EOF */
1345 if (lex_error!=0) return lex_error; else return LL_EOF;}
1346 .* { add_key_value(op); }
1347 %%
1348
1349
1350 int yyerror(char *s)
1351 {
1352 LOG(llevError, "%s: %s\n", s, yytext);
1353 return -1;
1354 }
1355
1356
1357 /* Our save file syntax is very simple, so we can use a very simple
1358 * processing mechanism here instead using something like bison
1359 * This skips over the space and returns the value, or "" if no value
1360 * is found. Modified 4/26/2000 to also strip spaces at end of
1361 * line
1362 */
1363 static char *yval()
1364 {
1365 static char *em="";
1366 char *cp,*end;
1367
1368 /* First skip over start of line, like animation or name */
1369 for (cp=yytext; *cp!=' '; cp++) {
1370 if (*cp=='\0') {
1371 return em;
1372 }
1373 }
1374
1375 /* Skip over whitespace */
1376 for (; *cp==' '; cp++) {
1377 if (*cp=='\0') {
1378 return em;
1379 }
1380 }
1381 /* Got last character before null and strip
1382 * off tailing whitespace
1383 */
1384 for (end=cp+strlen(cp)-1; *end==' '; end--) {
1385 if (end==cp) return em;
1386 *end='\0';
1387 }
1388 return cp;
1389 }
1390
1391
1392 /*
1393 * Loads an object from the given file-pointer.
1394 * Variables will be read and parsed and patched into the object
1395 * until the string "end" is reached, or the end of the file.
1396 *
1397 * bufstat is used to determine various file attributes:
1398 * LO_REPATE (0): We are reading from the same buffer as the last call.
1399 * LO_LINEMODE (1): file that is being read from is multi purpose (ie, other functions
1400 * will also be reading from this (treasure file, artifacts.)
1401 * LO_NEWFILE (2): This is the first read from a particular file, so the buffers should
1402 * be reset.
1403 * LO_NOREAD (3): Reset the buffers, but don't read from it. (op can be null)
1404 *
1405 */
1406
1407 int load_object(FILE *fp, object *op, int bufstate, int map_flags) {
1408 int retval;
1409 char inbuf[MAX_BUF];
1410
1411 strcpy(msgbuf, "");
1412 strcpy(lorebuf, "");
1413 if (bufstate==LO_NEWFILE || bufstate==LO_NOREAD) {
1414 /* LOG(llevDebug,"Switching lex buffers\n");*/
1415 yy_delete_buffer(YY_CURRENT_BUFFER);
1416 yy_switch_to_buffer(yy_create_buffer(fp, YY_BUF_SIZE));
1417 if (bufstate==LO_NOREAD) return LL_NORMAL;
1418 }
1419 if (bufstate==LO_LINEMODE) {
1420 YY_BUFFER_STATE yybufstate;
1421 while (fgets(inbuf, MAX_BUF-3, fp)) {
1422 yybufstate=yy_scan_string(inbuf);
1423 retval=lex_load(op, map_flags);
1424 yy_delete_buffer(yybufstate);
1425 if (retval==LL_NORMAL) return retval;
1426 }
1427 LOG(llevDebug,"Got eof while scanning strings\n");
1428 return LL_EOF;
1429 }
1430
1431 retval=lex_load(op, map_flags);
1432 if (op->current_weapon_script != NULL)
1433 {
1434 op->current_weapon = find_best_weapon_used_match(op, op->current_weapon_script);
1435 LOG(llevDebug, "CurrentWeapon Loaded !\n");
1436 };
1437
1438 /* LOG(llevDebug," load completed, object=%s\n",op->name);*/
1439 return retval;
1440 }
1441
1442
1443 /* This takes a buffer, scans it for variables, and sets those variables
1444 * as appropriate in op.
1445 *
1446 * This function appears to be used in only 2 places - in crossedit to
1447 * override values and in c_wiz to mutate values.
1448 */
1449 int set_variable(object *op,char *buf) {
1450 YY_BUFFER_STATE yybufstate,yycurbuf=YY_CURRENT_BUFFER;
1451 int retval;
1452
1453 strcpy(msgbuf, "");
1454 strcpy(lorebuf, "");
1455 yy_push_state(INITIAL);
1456 yybufstate=yy_scan_string(buf);
1457 retval=lex_load(op,0);
1458 yy_switch_to_buffer(yycurbuf);
1459 yy_delete_buffer(yybufstate);
1460 yy_pop_state();
1461 return retval;
1462 }
1463
1464 /* Start of C code */
1465
1466 /* This array equates the FLAG_ values with the V_ values. Use -1 to
1467 * put gaps in the array that should not be processed.
1468 * The order matches the order of the define values in 'define.h'.
1469 */
1470 /* This is a list of pointers that correspond to the FLAG_.. values.
1471 * This is a simple 1:1 mapping - if FLAG_FRIENDLY is 15, then
1472 * the 15'th element of this array should match that name.
1473 * If an entry is NULL, that is a flag not to loaded/saved.
1474 */
1475 static const char *const flag_names[NUM_FLAGS+1] = {
1476 "alive", "wiz", NULL, NULL, "was_wiz", "applied", "unpaid",
1477 "can_use_shield", "no_pick", NULL /* walk_on*/, NULL /* no_pass */, /* 10 */
1478 "is_animated", NULL /* slow_move */,
1479 NULL /* flying */, "monster", "friendly", "generator",
1480 "is_thrown", "auto_apply", "treasure", "player sold", /* 20 */
1481 "see_invisible", "can_roll", "overlay_floor",
1482 "is_turnable", NULL /* walk_off */, NULL /* fly_on */,
1483 NULL /*fly_off*/, "is_used_up", "identified", "reflecting", /* 30 */
1484 "changing", "splitting", "hitback", "startequip",
1485 "blocksview", "undead", "scared", "unaggressive",
1486 "reflect_missile", "reflect_spell", /* 40 */
1487 "no_magic", "no_fix_player", "is_lightable", "tear_down",
1488 "run_away", NULL /*pass_thru */, NULL /*can_pass_thru*/,
1489 "pick_up", "unique", "no_drop", /* 50 */
1490 NULL /* wizcast*/, "can_cast_spell", "can_use_scroll", "can_use_range",
1491 "can_use_bow", "can_use_armour", "can_use_weapon",
1492 "can_use_ring", "has_ready_range", "has_ready_bow", /* 60 */
1493 "xrays", NULL, "is_floor", "lifesave", "no_strength", "sleep",
1494 "stand_still", "random_move", "only_attack", "confused", /* 70 */
1495 "stealth", NULL, NULL, "cursed", "damned",
1496 "see_anywhere", "known_magical", "known_cursed",
1497 "can_use_skill", "been_applied", /* 80 */
1498 "has_ready_scroll", "can_use_rod", NULL,
1499 "can_use_horn", "make_invisible", "inv_locked", "is_wooded",
1500 "is_hilly", "has_ready_skill", "has_ready_weapon", /* 90 */
1501 "no_skill_ident", "is_blind", "can_see_in_dark", "is_cauldron",
1502 "is_dust", "no_steal", "one_hit", NULL, "berserk", "neutral", /* 100 */
1503 "no_attack", "no_damage", NULL, NULL, "activate_on_push",
1504 "activate_on_release", "is_water", "use_content_on_gen", NULL, "is_buildable", /* 110 */
1505 NULL
1506 };
1507
1508
1509 /*
1510 * Initialises the array of variable-names. Needed before any
1511 * objects can be loaded. Called by init_library().
1512 */
1513
1514 void init_vars() {
1515 }
1516
1517 /*For get_ob_diff speed reason*/
1518 typedef struct {
1519 const char *name;
1520 int length;
1521 }genericname;
1522 static genericname evtnames[13]=
1523 {
1524 {"event_none ",11},
1525 {"event_apply ",12},
1526 {"event_attack ",13},
1527 {"event_death ",12},
1528 {"event_drop ",11},
1529 {"event_pickup ",13},
1530 {"event_say ",10},
1531 {"event_stop ",11},
1532 {"event_time ",11},
1533 {"event_throw ",12},
1534 {"event_trigger ",14},
1535 {"event_close ",12},
1536 {"event_timer ",12}
1537 } ;
1538
1539 static genericname plgnames[13]=
1540 {
1541 {"event_none_plugin ",18},
1542 {"event_apply_plugin ",19},
1543 {"event_attack_plugin ",20},
1544 {"event_death_plugin ",19},
1545 {"event_drop_plugin ",18},
1546 {"event_pickup_plugin ",20},
1547 {"event_say_plugin ",17},
1548 {"event_stop_plugin ",18},
1549 {"event_time_plugin ",18},
1550 {"event_throw_plugin ",19},
1551 {"event_trigger_plugin ",21},
1552 {"event_close_plugin ",19},
1553 {"event_timer_plugin ",19}
1554 };
1555
1556 static genericname plgoptions[13]=
1557 {
1558 {"event_none_options ",19},
1559 {"event_apply_options ",20},
1560 {"event_attack_options ",21},
1561 {"event_death_options ",20},
1562 {"event_drop_options ",19},
1563 {"event_pickup_options ",21},
1564 {"event_say_options ",18},
1565 {"event_stop_options ",19},
1566 {"event_time_options ",19},
1567 {"event_throw_options ",20},
1568 {"event_trigger_options ",22},
1569 {"event_close_options ",20},
1570 {"event_timer_options ",20}
1571 };
1572
1573 /* This returns a string of the integer movement type */
1574 static char* get_string_move_type(MoveType mt)
1575 {
1576 static char retbuf[MAX_BUF], retbuf_all[MAX_BUF];
1577 int i, all_count=0, count;
1578
1579 strcpy(retbuf,"");
1580 strcpy(retbuf_all," all");
1581
1582 /* Quick check, and probably fairly common */
1583 if (mt == MOVE_ALL) return retbuf_all+1;
1584 if (mt == 0) {
1585 strcpy(retbuf,"0");
1586 return retbuf;
1587 }
1588
1589 /* We basically slide the bits down. Why look at MOVE_ALL?
1590 * because we may want to return a string like 'all -swim',
1591 * and if we just looked at mt, we couldn't get that.
1592 */
1593 for (i=MOVE_ALL, count=0; i!=0; i >>= 1, count++) {
1594 if (mt & (1<<count)) {
1595 strcat(retbuf, " ");
1596 strcat(retbuf, move_name[count]);
1597 } else {
1598 strcat(retbuf_all, " -");
1599 strcat(retbuf_all, move_name[count]);
1600 all_count++;
1601 }
1602 }
1603 /* Basically, if there is a single negation, return it, eg
1604 * 'all -swim'. But more than that, just return the
1605 * enumerated values. It doesn't make sense to return
1606 * 'all -walk -fly_low' - it is shorter to return 'fly_high swim'
1607 */
1608 if (all_count <=1) return retbuf_all+1;
1609 else return retbuf+1;
1610 }
1611
1612
1613 /*
1614 * Returns a pointer to a static string which contains all variables
1615 * which are different in the two given objects. op is the what object
1616 * the different values will be taken from. This function is
1617 * typically used to dump objects (op2=empty object), or to save objects
1618 * (op2 is the objects original archetype)
1619 * Note by MSW 2003-09-22: It's a bug that we need to pass entrysize -
1620 * we should use strlen entryname instead. Any smart compiler should
1621 * optimize that out.
1622 */
1623
1624
1625 /*static int eol_size=strlen("\n");*/
1626 static int eol_size=sizeof("\n")-1; /*Substract 1 to suppress terminal 0*/
1627 #define ADD_STRINGLINE_ENTRY(buf__,entryname__,entryvalue__,entrysize__){\
1628 FAST_STRNCAT(buf__,entryname__,entrysize__);\
1629 FAST_STRCAT(buf__,entryvalue__);\
1630 FAST_STRNCAT(buf__,"\n",eol_size);}
1631 #define FAST_SAVE_LONG(buf__,entryname__,entryvalue__,entrysize__) \
1632 ADD_STRINGLINE_ENTRY(buf__,entryname__,ltostr10(entryvalue__),entrysize__)
1633 #define FAST_SAVE_DOUBLE(buf__,entryname__,entryvalue__,entrysize__) \
1634 ADD_STRINGLINE_ENTRY(buf__,entryname__,doubletostr10(entryvalue__),entrysize__)
1635
1636
1637
1638 char *get_ob_diff(object *op,object *op2) {/* I plan to optimize this heavily */
1639
1640 /* Too late, have done it already :P
1641 * Tchize
1642 */
1643
1644 /*
1645 * A bit of explantion on strings handling in this function:
1646 * buf is never null terminated until the end. So
1647 * works only with buf2 and fastbuf. What concern fastbuf,
1648 * use ONLY through the FAST macros. Classical C string handling
1649 * functions will fail since it is a pointer to the end of the
1650 * string.
1651 * NEVER touch buf between PREPARE_FASTCAT(buf) and
1652 * FINISH_FASTCAT(buf)
1653 */
1654 static int already_run = 0;
1655 static int flag_lens[NUM_FLAGS];
1656 char buf2[4096]; // / was HUFE_BUF, which was hugely incorrect, as is this value, but much less so
1657 static char buf[128*1024]; // < the assumption is that every object always fits. fixing this bug, however
1658 char* fastbuf; // \ requires a large rewrite of the code, so its left to the next total rewrite.
1659 int tmp;
1660 int i;
1661 event *etmp;
1662 event *etmp2;
1663 key_value * my_field;
1664 key_value * arch_field;
1665
1666 /*first init this function if first call*/
1667 if (!already_run){
1668 for (i=0;i<NUM_FLAGS;i++)
1669 flag_lens[i]=flag_names[i]?strlen(flag_names[i]):0; /* some flags may be null? :/*/
1670 already_run=1;
1671 }
1672 buf[0]='\0';
1673 fastbuf=PREPARE_FASTCAT(buf);
1674
1675 /* This saves the key/value lists. We do it first so that any
1676 * keys that match field names will be overwritten by the loader.
1677 */
1678 for (my_field = op->key_values; my_field != NULL; my_field = my_field->next) {
1679 /* Find the field in the opposing member. */
1680 arch_field = get_ob_key_link(op2, my_field->key);
1681
1682 /* If there's no partnering field, or it's got a different value, save our field. */
1683 if (arch_field == NULL || my_field->value != arch_field->value) {
1684 FAST_STRCAT(fastbuf, my_field->key);
1685 FAST_STRNCAT(fastbuf, " ", 1);
1686 /* If this is null, then saving it as a space should
1687 * cause it to be null again.
1688 */
1689 if (my_field->value) FAST_STRCAT(fastbuf, my_field->value);
1690 FAST_STRNCAT(fastbuf, "\n", eol_size);
1691 }
1692 }
1693 /* We don't need to worry about the arch's extra fields - they
1694 * will get taken care of the copy_object function.
1695 */
1696
1697
1698 if(op->name && op->name!=op2->name) {
1699 ADD_STRINGLINE_ENTRY(fastbuf,"name ",op->name,5);
1700 }
1701 if(op->name_pl && op->name_pl!=op2->name_pl) {
1702 ADD_STRINGLINE_ENTRY(fastbuf,"name_pl ",op->name_pl,8);
1703 }
1704 if(op->custom_name && op->custom_name!=op2->custom_name) {
1705 ADD_STRINGLINE_ENTRY(fastbuf,"custom_name ",op->custom_name,12);
1706 }
1707 if(op->title && op->title!=op2->title) {
1708 ADD_STRINGLINE_ENTRY(fastbuf,"title ",op->title,6);
1709 }
1710 if(op->race && op->race!=op2->race) {
1711 ADD_STRINGLINE_ENTRY(fastbuf,"race ",op->race,5);
1712 }
1713 if(op->slaying && op->slaying!=op2->slaying) {
1714 ADD_STRINGLINE_ENTRY(fastbuf,"slaying ",op->slaying,8);
1715 }
1716 if(op->skill && op->skill!=op2->skill) {
1717 ADD_STRINGLINE_ENTRY(fastbuf,"skill ",op->skill,6);
1718 }
1719 if(op->msg && op->msg!=op2->msg) {
1720 FAST_STRNCAT(fastbuf,"msg\n",3+eol_size);
1721 FAST_STRCAT(fastbuf,op->msg);
1722 FAST_STRNCAT(fastbuf,"endmsg\n",6+eol_size);
1723 }
1724 if(op->lore && op->lore!=op2->lore) {
1725 FAST_STRNCAT(fastbuf,"lore\n",4+eol_size);
1726 FAST_STRCAT(fastbuf,op->lore);
1727 FAST_STRNCAT(fastbuf,"endlore\n",7+eol_size);
1728
1729 }
1730 if(op->other_arch!=op2->other_arch&&op->other_arch!=NULL &&
1731 op->other_arch->name) {
1732 ADD_STRINGLINE_ENTRY(fastbuf,"other_arch ",op->other_arch->name,11);
1733 }
1734 if(op->face!=op2->face) {
1735 ADD_STRINGLINE_ENTRY(fastbuf,"face ",op->face->name,5);
1736 }
1737
1738 for(etmp=op->events;etmp!=NULL;etmp=etmp->next)
1739 {
1740 /* First we find the event for the reference object */
1741 etmp2=find_event(op2,etmp->type);
1742 if ((etmp->hook != NULL) && ((etmp2 == NULL) || (etmp2->hook == NULL) || (strcmp(etmp2->hook,etmp->hook))))
1743 /* Either there's no matching event in the reference object,
1744 * or the hook is different */
1745 {
1746 ADD_STRINGLINE_ENTRY(fastbuf,evtnames[etmp->type].name,etmp->hook,evtnames[etmp->type].length);
1747 }
1748 if ((etmp->plugin != NULL) && ((etmp2 == NULL) || (etmp2->plugin == NULL) || (strcmp(etmp2->plugin,etmp->plugin))))
1749 {
1750
1751 ADD_STRINGLINE_ENTRY(fastbuf,plgnames[etmp->type].name,etmp->plugin,plgnames[etmp->type].length);
1752 }
1753 if ((etmp->options != NULL) && ((etmp2 == NULL) || (etmp2->options == NULL) || (strcmp(etmp2->options,etmp->options))))
1754 {
1755 ADD_STRINGLINE_ENTRY(fastbuf,plgoptions[etmp->type].name,etmp->options,plgoptions[etmp->type].length);
1756 }
1757
1758 }
1759
1760 if (op->animation_id != op2->animation_id) {
1761 if (op->animation_id) {
1762 ADD_STRINGLINE_ENTRY(fastbuf,"animation ",animations[GET_ANIM_ID(op)].name,10);
1763 if ( ! QUERY_FLAG (op, FLAG_ANIMATE)) {
1764 FAST_STRNCAT(fastbuf,"is_animated 0\n",13+eol_size);
1765 }
1766 } else {
1767 FAST_STRNCAT(fastbuf,"animation NONE\n",14+eol_size);
1768 }
1769 }
1770 if(op->stats.Str!=op2->stats.Str)
1771 FAST_SAVE_LONG(fastbuf,"Str ",op->stats.Str,4);
1772 if(op->stats.Dex!=op2->stats.Dex)
1773 FAST_SAVE_LONG(fastbuf,"Dex ",op->stats.Dex,4);
1774 if(op->stats.Con!=op2->stats.Con)
1775 FAST_SAVE_LONG(fastbuf,"Con ",op->stats.Con,4);
1776 if(op->stats.Wis!=op2->stats.Wis)
1777 FAST_SAVE_LONG(fastbuf,"Wis ",op->stats.Wis,4);
1778 if(op->stats.Pow!=op2->stats.Pow)
1779 FAST_SAVE_LONG(fastbuf,"Pow ",op->stats.Pow,4);
1780 if(op->stats.Cha!=op2->stats.Cha)
1781 FAST_SAVE_LONG(fastbuf,"Cha ",op->stats.Cha,4);
1782 if(op->stats.Int!=op2->stats.Int)
1783 FAST_SAVE_LONG(fastbuf,"Int ",op->stats.Int,4);
1784 if(op->stats.hp!=op2->stats.hp)
1785 FAST_SAVE_LONG(fastbuf,"hp ",op->stats.hp,3);
1786 if(op->stats.maxhp!=op2->stats.maxhp)
1787 FAST_SAVE_LONG(fastbuf,"maxhp ",op->stats.maxhp,6);
1788 if(op->stats.sp!=op2->stats.sp)
1789 FAST_SAVE_LONG(fastbuf,"sp ",op->stats.sp,3);
1790 if(op->stats.maxsp!=op2->stats.maxsp)
1791 FAST_SAVE_LONG(fastbuf,"maxsp ",op->stats.maxsp,6);
1792 if(op->stats.grace!=op2->stats.grace)
1793 FAST_SAVE_LONG(fastbuf,"grace ",op->stats.grace,6);
1794 if(op->stats.maxgrace!=op2->stats.maxgrace)
1795 FAST_SAVE_LONG(fastbuf,"maxgrace ",op->stats.maxgrace,9);
1796
1797 if(op->stats.exp!=op2->stats.exp) {
1798 #ifndef WIN32
1799 sprintf(buf2,"%lld", op->stats.exp);
1800 #else
1801 sprintf(buf2,"%I64d", op->stats.exp);
1802 #endif
1803 ADD_STRINGLINE_ENTRY(fastbuf,"exp ", buf2, 4);
1804 }
1805
1806 if(op->perm_exp!=op2->perm_exp) {
1807 #ifndef WIN32
1808 sprintf(buf2,"%lld", op->perm_exp);
1809 #else
1810 sprintf(buf2,"%I64d", op->perm_exp);
1811 #endif
1812 ADD_STRINGLINE_ENTRY(fastbuf,"perm_exp ", buf2, 9);
1813 }
1814
1815 if(op->expmul!=op2->expmul)
1816 FAST_SAVE_DOUBLE(fastbuf,"expmul ",op->expmul,7);
1817 if(op->stats.food!=op2->stats.food)
1818 FAST_SAVE_LONG(fastbuf,"food ",op->stats.food,5);
1819 if(op->stats.dam!=op2->stats.dam)
1820 FAST_SAVE_LONG(fastbuf,"dam ",op->stats.dam,4);
1821 if(op->stats.luck!=op2->stats.luck)
1822 FAST_SAVE_LONG(fastbuf,"luck ",op->stats.luck,5);
1823 if(op->stats.wc!=op2->stats.wc)
1824 FAST_SAVE_LONG(fastbuf,"wc ",op->stats.wc,3);
1825 if(op->stats.ac!=op2->stats.ac)
1826 FAST_SAVE_LONG(fastbuf,"ac ",op->stats.ac,3);
1827 if(op->x!=op2->x)
1828 FAST_SAVE_LONG(fastbuf,"x ",op->x,2);
1829 if(op->y!=op2->y)
1830 FAST_SAVE_LONG(fastbuf,"y ",op->y,2);
1831 if(op->speed!=op2->speed) {
1832 FAST_SAVE_DOUBLE(fastbuf,"speed ",op->speed,6);
1833 }
1834 if(op->speed > 0 && op->speed_left!=op2->speed_left) {
1835 FAST_SAVE_DOUBLE(fastbuf,"speed_left ",op->speed_left,11);
1836 }
1837 if(op->move_status != op2->move_status)
1838 FAST_SAVE_LONG(fastbuf,"move_state ",op->move_status,11);
1839 if(op->attack_movement != op2->attack_movement)
1840 FAST_SAVE_LONG(fastbuf,"attack_movement ",op->attack_movement,16);
1841 if(op->nrof!=op2->nrof)
1842 FAST_SAVE_LONG(fastbuf,"nrof ",op->nrof,5);
1843 if(op->level!=op2->level)
1844 FAST_SAVE_LONG(fastbuf,"level ",op->level,6);
1845 if(op->direction!=op2->direction)
1846 FAST_SAVE_LONG(fastbuf,"direction ",op->direction,10);
1847 if(op->type!=op2->type)
1848 FAST_SAVE_LONG(fastbuf,"type ",op->type,5);
1849 if(op->subtype!=op2->subtype)
1850 FAST_SAVE_LONG(fastbuf,"subtype ",op->subtype,8);
1851 if(op->attacktype!=op2->attacktype)
1852 FAST_SAVE_LONG(fastbuf,"attacktype ",op->attacktype,11);
1853
1854 for (tmp=0; tmp < NROFATTACKS; tmp++) {
1855 if (op->resist[tmp] != op2->resist[tmp]) {
1856 FAST_STRNCAT(fastbuf,"resist_",7);
1857 FAST_SAVE_LONG(fastbuf,resist_save[tmp],op->resist[tmp],strlen(resist_save[tmp]));
1858 }
1859 }
1860
1861 if(op->path_attuned!=op2->path_attuned)
1862 FAST_SAVE_LONG(fastbuf,"path_attuned ",op->path_attuned,13);
1863 if(op->path_repelled!=op2->path_repelled)
1864 FAST_SAVE_LONG(fastbuf,"path_repelled ",op->path_repelled,14);
1865 if(op->path_denied!=op2->path_denied)
1866 FAST_SAVE_LONG(fastbuf,"path_denied ",op->path_denied,12);
1867 if(op->material!=op2->material)
1868 FAST_SAVE_LONG(fastbuf,"material ",op->material,9);
1869 if(op->materialname && op->materialname!=op2->materialname) {
1870 ADD_STRINGLINE_ENTRY(fastbuf,"materialname ",op->materialname,13);
1871 }
1872 if(op->value!=op2->value)
1873 FAST_SAVE_LONG(fastbuf,"value ",op->value,6);
1874 if(op->carrying!=op2->carrying)
1875 FAST_SAVE_LONG(fastbuf,"carrying ",op->carrying,9);
1876 if(op->weight!=op2->weight)
1877 FAST_SAVE_LONG(fastbuf,"weight ",op->weight,7);
1878 if(op->invisible!=op2->invisible)
1879 FAST_SAVE_LONG(fastbuf,"invisible ",op->invisible,10);
1880 if(op->state!=op2->state)
1881 FAST_SAVE_LONG(fastbuf,"state ",op->state,6);
1882 if(op->magic!=op2->magic)
1883 FAST_SAVE_LONG(fastbuf,"magic ",op->magic,6);
1884 if(op->last_heal!=op2->last_heal)
1885 FAST_SAVE_LONG(fastbuf,"last_heal ",op->last_heal,10);
1886 if(op->last_sp!=op2->last_sp)
1887 FAST_SAVE_LONG(fastbuf,"last_sp ",op->last_sp,8);
1888 if(op->last_grace!=op2->last_grace)
1889 FAST_SAVE_LONG(fastbuf,"last_grace ",op->last_grace,11);
1890 if(op->last_eat!=op2->last_eat)
1891 FAST_SAVE_LONG(fastbuf,"last_eat ",op->last_eat,9);
1892 if(QUERY_FLAG(op,FLAG_IS_LINKED) && (tmp = get_button_value(op)))
1893 FAST_SAVE_LONG(fastbuf,"connected ",tmp,10);
1894 if(op->glow_radius!=op2->glow_radius)
1895 FAST_SAVE_LONG(fastbuf,"glow_radius ",op->glow_radius,12);
1896 if (op->randomitems!=op2->randomitems) {
1897 ADD_STRINGLINE_ENTRY(fastbuf,"randomitems ",(op->randomitems?op->randomitems->name:"none"),12);
1898 }
1899 #ifdef NPC_PROG
1900 if(op->npc_status!=op2->npc_status)
1901 FAST_SAVE_LONG(fastbuf,"npc_status ",op->npc_status,11);
1902 if(op->npc_program!=op2->npc_program)
1903 FAST_SAVE_LONG(fastbuf,"npc_program ",op->npc_program,12);
1904 #endif
1905
1906
1907 if(op->run_away!=op2->run_away)
1908 FAST_SAVE_LONG(fastbuf,"run_away ",op->run_away,9);
1909 if(op->pick_up!=op2->pick_up)
1910 FAST_SAVE_LONG(fastbuf,"pick_up ",op->pick_up,8);
1911 if(op->weight_limit!=op2->weight_limit)
1912 FAST_SAVE_LONG(fastbuf,"container ",op->weight_limit,10);
1913 if (op->will_apply!=op2->will_apply)
1914 FAST_SAVE_LONG(fastbuf,"will_apply ",op->will_apply,11);
1915 if(op->smoothlevel!=op2->smoothlevel)
1916 FAST_SAVE_LONG(fastbuf,"smoothlevel ",op->smoothlevel,12);
1917
1918 if (op->current_weapon_script!=op2->current_weapon_script){
1919 ADD_STRINGLINE_ENTRY(fastbuf,"current_weapon_script ",op->current_weapon_script,22);
1920 };
1921
1922 if(op->weapontype && op->weapontype!=op2->weapontype) {
1923 FAST_SAVE_LONG(fastbuf,"weapontype ",op->weapontype,11);
1924 }
1925 if(op->tooltype && op->tooltype!=op2->tooltype) {
1926 FAST_SAVE_LONG(fastbuf,"tooltype ",op->tooltype,9);
1927 }
1928 if (op->elevation && op->elevation != op2->elevation) {
1929 FAST_SAVE_LONG(fastbuf,"elevation ",op->elevation,10);
1930 }
1931 if (op->client_type && op->client_type != op2->client_type) {
1932 FAST_SAVE_LONG(fastbuf,"client_type ",op->client_type,12);
1933 }
1934
1935 if (op->item_power != op2->item_power) {
1936 FAST_SAVE_LONG(fastbuf,"item_power ",op->item_power,11);
1937 }
1938
1939 if (op->duration != op2->duration)
1940 FAST_SAVE_LONG(fastbuf,"duration ",op->duration,9);
1941
1942 if (op->range != op2->range)
1943 FAST_SAVE_LONG(fastbuf,"range ",op->range,6);
1944
1945 if (op->range_modifier != op2->range_modifier)
1946 FAST_SAVE_LONG(fastbuf,"range_modifier ",op->range_modifier,15);
1947
1948 if (op->duration_modifier != op2->duration_modifier)
1949 FAST_SAVE_LONG(fastbuf,"duration_modifier ", op->duration_modifier,18);
1950
1951 if (op->dam_modifier != op2->dam_modifier)
1952 FAST_SAVE_LONG(fastbuf,"dam_modifier ", op->dam_modifier,13);
1953
1954 if (op->gen_sp_armour != op2->gen_sp_armour) {
1955 FAST_SAVE_LONG(fastbuf,"gen_sp_armour ",op->gen_sp_armour,14);
1956 }
1957
1958 /* I've kept the old int move type saving code commented out.
1959 * In an ideal world, we'd know if we want to do a quick
1960 * save (say to a temp map, where we don't care about strings),
1961 * or a slower save/dm dump, where printing out strings is handy.
1962 */
1963 if (op->move_type != op2->move_type) {
1964 /*FAST_SAVE_LONG(fastbuf,"move_type ",op->move_type,10)*/
1965 ADD_STRINGLINE_ENTRY(fastbuf,"move_type ",
1966 get_string_move_type(op->move_type),
1967 10);
1968 }
1969 if (op->move_block != op2->move_block) {
1970 /*FAST_SAVE_LONG(fastbuf,"move_block ",op->move_block,11)*/
1971 ADD_STRINGLINE_ENTRY(fastbuf,"move_block ",
1972 get_string_move_type(op->move_block),
1973 11);
1974 }
1975 if (op->move_allow != op2->move_allow) {
1976 /*FAST_SAVE_LONG(fastbuf,"move_allow ",op->move_allow,11);*/
1977 ADD_STRINGLINE_ENTRY(fastbuf,"move_allow ",
1978 get_string_move_type(op->move_allow),
1979 11);
1980 }
1981 if (op->move_on != op2->move_on) {
1982 /*FAST_SAVE_LONG(fastbuf,"move_on ",op->move_on,8);*/
1983 ADD_STRINGLINE_ENTRY(fastbuf,"move_on ",
1984 get_string_move_type(op->move_on),
1985 8);
1986 }
1987 if (op->move_off != op2->move_off) {
1988 /*FAST_SAVE_LONG(fastbuf,"move_off ",op->move_off,9);*/
1989 ADD_STRINGLINE_ENTRY(fastbuf,"move_off ",
1990 get_string_move_type(op->move_off),
1991 9);
1992 }
1993 if (op->move_slow != op2->move_slow) {
1994 /*FAST_SAVE_LONG(fastbuf,"move_slow ",op->move_slow,10);*/
1995 ADD_STRINGLINE_ENTRY(fastbuf,"move_slow ",
1996 get_string_move_type(op->move_slow),
1997 10);
1998 }
1999
2000 if (op->move_slow_penalty != op2->move_slow_penalty) {
2001 FAST_SAVE_LONG(fastbuf,"move_slow_penalty ",(long) op->move_slow_penalty,18);
2002 }
2003
2004 if (!COMPARE_FLAGS(op,op2)) {
2005 for (tmp=0; tmp <= NUM_FLAGS; tmp++) {
2006 if (flag_names[tmp] && (QUERY_FLAG(op, tmp) != QUERY_FLAG(op2, tmp))) {
2007 ADD_STRINGLINE_ENTRY(fastbuf,flag_names[tmp],QUERY_FLAG(op, tmp)?" 1":" 0",flag_lens[tmp]);
2008 }
2009 }
2010 }
2011
2012 /* Save body locations */
2013 for (i=0; i<NUM_BODY_LOCATIONS; i++) {
2014 if (op->body_info[i] != op2->body_info[i]) {
2015 FAST_STRCAT(fastbuf,body_locations[i].save_name);
2016 FAST_SAVE_LONG(fastbuf," ",op->body_info[i],1);
2017 }
2018 }
2019 FINISH_FASTCAT(fastbuf);
2020 if(buf[0]=='\0') /*did not cat anything...*/
2021 return NULL;
2022
2023 return buf;
2024 }
2025
2026 /*
2027 * Dumps all variables in an object to a file.
2028 * If bit 0 of flag is set, unpaid objects will be saved. As of now,
2029 * the only place this is not set is when saving the player.
2030 * If bit 1 of flag is set, don't remove the object after save. As of now,
2031 * all of the callers are setting this.
2032 */
2033
2034 void save_object(FILE *fp,object *op, int flag) {
2035 archetype *at;
2036 char *cp;
2037 object *tmp,*old;
2038
2039 /* Even if the object does have an owner, it would seem that we should
2040 * still save it.
2041 */
2042 if(op->owner!=NULL || fp == NULL)
2043 return;
2044
2045 /* If it is unpaid and we don't want to save those, just return. */
2046 if(!(flag&1)&&(QUERY_FLAG(op, FLAG_UNPAID))) {
2047 return;
2048 }
2049
2050 if((at=op->arch)==NULL) at=empty_archetype;
2051 fprintf(fp,"arch %s\n",at->name);
2052
2053 if((cp=get_ob_diff(op,&at->clone))!=NULL)
2054 fputs(cp,fp); /* We really should do some status checking on this */
2055
2056 /* Eneq(@csd.uu.se): Added this to allow containers being saved with contents*/
2057
2058 old=NULL;
2059
2060 if (flag & 2 )
2061 for(tmp=op->inv;tmp!=NULL;tmp=tmp->below)
2062 save_object(fp,tmp,flag);
2063
2064 /* Slightly different logic because tmp/op will be removed by
2065 * the save_object we call. So we just keep looking at op->inv
2066 * until there is nothing left. In theory, the variable old
2067 * should not be needed, as recursive loops shouldn't happen.
2068 */
2069 else while ((tmp=op->inv)!=NULL) {
2070 if(old==tmp) {
2071 LOG(llevError," Recursive loop in inventory\n");
2072 break;
2073 }
2074 save_object(fp,tmp,flag);
2075 old=tmp;
2076 }
2077
2078 if (!(flag&2)) {
2079 remove_ob(op);
2080 free_object (op);
2081 }
2082
2083 fprintf(fp,"end\n");
2084 }
2085
2086 void insert_event(object* op, int etype, char *ehook, char *eplug, char *eoptions)
2087 {
2088 event *evt;
2089 event *tmp;
2090
2091 evt = find_event(op,etype);
2092 if (evt == NULL)
2093 {
2094 evt = (event *)malloc(sizeof(event));
2095 evt->next = NULL;
2096 evt->type = etype;
2097 evt->hook = NULL;
2098 evt->plugin = NULL;
2099 evt->options = NULL;
2100 if (op->events==NULL)
2101 {
2102 op->events=evt;
2103 }
2104 else
2105 {
2106 for(tmp=op->events;;tmp=tmp->next)
2107 {
2108 if (tmp->next == NULL)
2109 {
2110 tmp->next = evt;
2111 break;
2112 }
2113 }
2114 }
2115 }
2116 if (ehook != NULL)
2117 FREE_AND_COPY(evt->hook,ehook);
2118 if (eplug != NULL)
2119 FREE_AND_COPY(evt->plugin,eplug);
2120 if (eoptions != NULL)
2121 FREE_AND_COPY(evt->options,eoptions);
2122 }
2123
2124 event* find_event(object* op, int etype)
2125 {
2126 event *found;
2127 for(found=op->events;found!=NULL;found=found->next)
2128 {
2129 if (found->type == etype)
2130 return found;
2131 }
2132 return NULL;
2133 }