ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/loader.l
Revision: 1.1.1.3 (vendor branch)
Committed: Wed Mar 15 14:04:37 2006 UTC (18 years, 2 months ago) by elmex
Branch: UPSTREAM
CVS Tags: UPSTREAM_2006_03_15
Changes since 1.1.1.2: +14 -14 lines
Log Message:
cvs -z9 -d:ext:elmex@cvs.schmorp.de:/schmorpforge import cf.schmorp.de UPSTREAM UPSTREAM_2006_03_15

File Contents

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