Debian Codegraph @

common/loader.l

raw
1 %{
2 /*
3 * Crossfire -- cooperative multi-player graphical RPG and adventure game
4 *
5 * Copyright (c) 1999-2014 Mark Wedel and the Crossfire Development Team
6 * Copyright (c) 1992 Frank Tore Johansen
7 *
8 * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
9 * welcome to redistribute it under certain conditions. For details, please
10 * see COPYING and LICENSE.
11 *
12 * The authors can be reached via e-mail at <[email protected]>.
13 */
14
15 /* Eneq(@csd.uu.se): Added weight-modifiers in environment of objects.
16 object_sub/add_weight will transcend the environment updating the carrying
17 variable. */
18
19 #include "global.h"
20
21 #include <ctype.h>
22
23 #include "loader.h"
24 #include "newserver.h"
25 #include "sproto.h"
26 #include "stringbuffer.h"
27
28 #define YY_DECL int lex_load(int *depth, object **items, int maxdepth, int map_flags, int linemode)
29
30 static char *yval(void);
31
32 static int lex_error;
33 static char msgbuf[HUGE_BUF];
34 size_t msglen = 0, total_msglen = 0;
35 static char lorebuf[HUGE_BUF];
36
37 /**
38 * This table is only necessary to convert objects that existed before the
39 * spell object conversion to the new object. It was not practical
40 * to go through every mapping looking for every potion, rod, wand, etc
41 * that had a sp set and update to the new value. So this maps the
42 * old spell numbers to the name of the new archs.
43 * If you are adding a new spell, you should not modify this - your
44 * new spell won't have been used, and thus won't have any legacy object.
45 * NULL entries in this table are valid - to denote objects that should
46 * not be updated for whatever reason.
47 *
48 * @todo
49 * is this still required? it's used, but can it happen?
50 */
51 const char *const spell_mapping[] = {
52 "spell_magic_bullet", /* 0 */
53 "spell_small_fireball", /* 1 */
54 "spell_medium_fireball", /* 2 */
55 "spell_large_fireball", /* 3 */
56 "spell_burning_hands", /* 4 */
57 "spell_sm_lightning", /* 5 */
58 "spell_large_lightning", /* 6 */
59 "spell_magic_missile", /* 7 */
60 "spell_create_bomb", /* 8 */
61 "spell_summon_golem", /* 9 */
62 "spell_summon_fire_elemental", /* 10 */
63 "spell_summon_earth_elemental", /* 11 */
64 "spell_summon_water_elemental", /* 12 */
65 "spell_summon_air_elemental", /* 13 */
66 "spell_dimension_door", /* 14 */
67 "spell_create_earth_wall", /* 15 */
68 "spell_paralyze", /* 16 */
69 "spell_icestorm", /* 17 */
70 "spell_magic_mapping", /* 18 */
71 "spell_turn_undead", /* 19 */
72 "spell_fear", /* 20 */
73 "spell_poison_cloud", /* 21 */
74 "spell_wonder", /* 22 */
75 "spell_destruction", /* 23 */
76 "spell_perceive_self", /* 24 */
77 "spell_word_of_recall", /* 25 */
78 "spell_invisible", /* 26 */
79 "spell_invisible_to_undead", /* 27 */
80 "spell_probe", /* 28 */
81 "spell_lg_magic_bullet", /* 29 */
82 "spell_improved_invisibility", /* 30 */
83 "spell_holy_word", /* 31 */
84 "spell_minor_healing", /* 32 */
85 "spell_medium_healing", /* 33 */
86 "spell_major_healing", /* 34 */
87 "spell_heal", /* 35 */
88 "spell_create_food", /* 36 */
89 "spell_earth_to_dust", /* 37 */
90 "spell_armour", /* 38 */
91 "spell_strength", /* 39 */
92 "spell_dexterity", /* 40 */
93 "spell_constitution", /* 41 */
94 "spell_charisma", /* 42 */
95 "spell_create_fire_wall", /* 43 */
96 "spell_create_frost_wall", /* 44 */
97 "spell_protection_from_cold", /* 45 */
98 "spell_protection_from_electricity", /* 46 */
99 "spell_protection_from_fire", /* 47 */
100 "spell_protection_from_poison", /* 48 */
101 "spell_protection_from_slow", /* 49 */
102 "spell_protection_from_paralysis", /* 50 */
103 "spell_protection_from_draining", /* 51 */
104 "spell_protection_from_magic", /* 52 */
105 "spell_protection_from_attack", /* 53 */
106 "spell_levitate", /* 54 */
107 "spell_small_speedball", /* 55 */
108 "spell_large_speedball", /* 56 */
109 "spell_hellfire", /* 57 */
110 "spell_dragonbreath", /* 58 */
111 "spell_large_icestorm", /* 59 */
112 "spell_charging", /* 60 */
113 "spell_polymorph", /* 61 */
114 "spell_cancellation", /* 62 */
115 "spell_confusion", /* 63 */
116 "spell_mass_confusion", /* 64 */
117 "spell_summon_pet_monster", /* 65 */
118 "spell_slow", /* 66 */
119 "spell_regenerate_spellpoints", /* 67 */
120 "spell_cure_poison", /* 68 */
121 "spell_protection_from_confusion", /* 69 */
122 "spell_protection_from_cancellation", /* 70 */
123 "spell_protection_from_depletion", /* 71 */
124 "spell_alchemy", /* 72 */
125 "spell_remove_curse", /* 73 */
126 "spell_remove_damnation", /* 74 */
127 "spell_identify", /* 75 */
128 "spell_detect_magic", /* 76 */
129 "spell_detect_monster", /* 77 */
130 "spell_detect_evil", /* 78 */
131 "spell_detect_curse", /* 79 */
132 "spell_heroism", /* 80 */
133 "spell_aggravation", /* 81 */
134 "spell_firebolt", /* 82 */
135 "spell_frostbolt", /* 83 */
136 "spell_shockwave", /* 84 */
137 "spell_color_spray", /* 85 */
138 "spell_haste", /* 86 */
139 "spell_face_of_death", /* 87 */
140 "spell_ball_lightning", /* 88 */
141 "spell_meteor_swarm", /* 89 */
142 "spell_comet", /* 90 */
143 "spell_mystic_fist", /* 91 */
144 "spell_raise_dead", /* 92 */
145 "spell_resurrection", /* 93 */
146 "spell_reincarnation", /* 94 */
147 "spell_immunity_to_cold", /* 95 */
148 "spell_immunity_to_electricity", /* 96 */
149 "spell_immunity_to_fire", /* 97 */
150 "spell_immunity_to_poison", /* 98 */
151 "spell_immunity_to_slow", /* 99 */
152 "spell_immunity_to_paralysis", /* 100 */
153 "spell_immunity_to_draining", /* 101 */
154 "spell_immunity_to_magic", /* 102 */
155 "spell_immunity_to_attack", /* 103 */
156 "spell_invulnerability", /* 104 */
157 "spell_defense", /* 105 */
158 "spell_rune_of_fire", /* 106 */
159 "spell_rune_of_frost", /* 107 */
160 "spell_rune_of_shocking", /* 108 */
161 "spell_rune_of_blasting", /* 109 */
162 "spell_rune_of_death", /* 110 */
163 "spell_marking_rune", /* 111 */
164 "spell_build_director", /* 112 */
165 "spell_create_pool_of_chaos", /* 113 */
166 "spell_build_bullet_wall", /* 114 */
167 "spell_build_lightning_wall", /* 115 */
168 "spell_build_fireball_wall", /* 116 */
169 "spell_magic_rune", /* 117 */
170 "spell_rune_of_magic_drain", /* 118 */
171 "spell_antimagic_rune", /* 119 */
172 "spell_rune_of_transference", /* 120 */
173 "spell_transference", /* 121 */
174 "spell_magic_drain", /* 122 */
175 "spell_counterspell", /* 123 */
176 "spell_disarm", /* 124 */
177 "spell_cure_confusion", /* 125 */
178 "spell_restoration", /* 126 */
179 "was summon evil monster", /* 127 */ /* Not implenented as nothing used it */
180 "spell_counterwall", /* 128 */
181 "spell_cause_light_wounds", /* 129 */
182 "spell_cause_medium_wounds", /* 130 */
183 "spell_cause_heavy_wounds", /* 131 */
184 "spell_charm_monsters", /* 132 */
185 "spell_banishment", /* 133 */
186 "spell_create_missile", /* 134 */
187 "spell_show_invisible", /* 135 */
188 "spell_xray", /* 136 */
189 "spell_pacify", /* 137 */
190 "spell_summon_fog", /* 138 */
191 "spell_steambolt", /* 139 */
192 "spell_command_undead", /* 140 */
193 "spell_holy_orb", /* 141 */
194 "spell_summon_avatar", /* 142 */
195 "spell_holy_possession", /* 143 */
196 "spell_bless", /* 144 */
197 "spell_curse", /* 145 */
198 "spell_regeneration", /* 146 */
199 "spell_consecrate", /* 147 */
200 "spell_summon_cult_monsters", /* 148 */
201 "spell_cause_critical_wounds", /* 149 */
202 "spell_holy_wrath", /* 150 */
203 "spell_retributive_strike", /* 151 */
204 "spell_finger_of_death", /* 152 */
205 "spell_insect_plague", /* 153 */
206 "spell_call_holy_servant", /* 154 */
207 "spell_wall_of_thorns", /* 155 */
208 "spell_staff_to_snake", /* 156 */
209 "spell_light", /* 157 */
210 "spell_darkness", /* 158 */
211 "spell_nightfall", /* 159 */
212 "spell_daylight", /* 160 */
213 "spell_sunspear", /* 161 */
214 "spell_faery_fire", /* 162 */
215 "spell_cure_blindness", /* 163 */
216 "spell_dark_vision", /* 164 */
217 "spell_bullet_swarm", /* 165 */
218 "spell_bullet_storm", /* 166 */
219 "spell_cause_many_wounds", /* 167 */
220 "spell_small_snowstorm", /* 168 */
221 "spell_medium_snowstorm", /* 169 */
222 "spell_large_snowstorm", /* 170 */
223 "spell_cure_disease", /* 171 */
224 "spell_cause_red_death", /* 172 */
225 "spell_cause_flu", /* 173 */
226 "spell_cause_black_death", /* 174 */
227 "spell_cause_leprosy", /* 175 */
228 "spell_cause_smallpox", /* 176 */
229 "spell_cause_white_death", /* 177 */
230 "spell_cause_anthrax", /* 178 */
231 "spell_cause_typhoid", /* 179 */
232 "spell_mana_blast", /* 180 */
233 "spell_small_manaball", /* 181 */
234 "spell_medium_manaball", /* 182 */
235 "spell_large_manaball", /* 183 */
236 "spell_manabolt", /* 184 */
237 "spell_dancing_sword", /* 185 */
238 "spell_animate_weapon", /* 186 */
239 "spell_cause_cold", /* 187 */
240 "spell_divine_shock", /* 188 */
241 "spell_windstorm", /* 189 */
242 "spell_sanctuary", /* 190 */
243 "spell_peace", /* 191 */
244 "spell_spiderweb", /* 192 */
245 "spell_conflict", /* 193 */
246 "spell_rage", /* 194 */
247 "spell_forked_lightning", /* 195 */
248 "spell_poison_fog", /* 196 */
249 "spell_flaming_aura", /* 197 */
250 "spell_vitriol", /* 198 */
251 "spell_vitriol_splash", /* 199 */
252 "spell_iron_skin", /* 200 */
253 "spell_wrathful_eye", /* 201 */
254 "spell_town_portal", /* 202 */
255 "spell_missile_swarm", /* 203 */
256 "spell_cause_rabies", /* 204 */
257 "spell_glyph", /* 205 */
258 NULL
259 };
260
261 /** Utility macro to transform a bit into a flag. */
262 #define SET_OR_CLEAR_FLAG(op, flag, val) \
263 { if (val) SET_FLAG(op, flag); else CLEAR_FLAG(op, flag); }
264
265 /**
266 * SET_RESIST is really only really needed for transition code. We normally
267 * don't care about multiple values overwriting each other, but this is
268 * to catch items that have multiple protection/immune/vulnerable.
269 * This can be simplified later on to just do the set after all the archs
270 * and maps have been updated.
271 * We always keep the last value because otherwise the value from the
272 * arch may take precedence.
273 * Unfortunately, we will report warnings here simply because an object has
274 * been modified from the arch.
275 */
276 #define SET_RESIST(op, type, val) op->resist[type] = val;
277
278
279 /** Next value as integer. */
280 #define IVAL atoi(yval())
281 /** Next value as float. */
282 #define FVAL atof(yval())
283 extern int arch_init;
284 extern int artifact_init;
285
286 /**
287 * Keep track of whether we're currently inside an object...end block. This
288 * might have been better designed as a separate start condition, but was
289 * added to give a warning when an object started before the previous ended.
290 */
291 static bool seen_object = false;
292
293 /**
294 * Fills in the body information for one slot.
295 *
296 * @param op
297 * object
298 * @param params
299 * the body part, which should be in the ::body_locations structure.
300 */
301 static void set_body_info(object *op, char *params) {
302 int i;
303 char *cp;
304
305 /* go to first space character */
306 for (cp = params; !isspace(*cp); cp++)
307 ;
308
309 *cp++ = 0; /* null it out */
310
311 for (i = 0; i < NUM_BODY_LOCATIONS; i++) {
312 if (!strcmp(params, body_locations[i].save_name)) {
313 op->body_info[i] = atoi(cp);
314 return; /* Only one line passed in params */
315 }
316 }
317 LOG(llevError, "set_body_info called with bogus params: %s\n", params);
318 }
319
320 /**
321 * This function checks the object after it has been loaded (when we
322 * get the 'end' in the input stream). This function can be used to
323 * deal with legacy objects where fields may have changed. It can also be used
324 * to check for objects to make sure there are no common errors.
325 *
326 * @param op
327 * object to check.
328 */
329 static void check_loaded_object(object *op) {
330 if (artifact_init)
331 /* Artifacts are special beasts, let's not check them. */
332 return;
333
334 if (!is_type_valid(op->type)) {
335 LOG(llevError, "Invalid type %d for %s\n", op->type, op->arch ? op->arch->name : op->name);
336 op->type = 0;
337 }
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) {
350 free_string(op->name_pl);
351 op->name_pl = NULL;
352 }
353 }
354 if (!op->name_pl && op->name)
355 op->name_pl = add_string(op->name);
356
357 /* objects now have a materialname. try to patch it in */
358 if (!(IS_WEAPON(op) && op->level > 0)) {
359 set_materialname(op);
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", op->name, op->body_info[1], op->skill);
372 }
373 }
374
375 /* spellbooks & runes use slaying. But not to arch name, but to spell name */
376 if ((op->type == SPELLBOOK || op->type == RUNE) && op->slaying && !op->inv && !arch_init) {
377 object *tmp;
378
379 tmp = create_archetype_by_object_name(op->slaying);
380 object_insert_in_ob(tmp, op);
381 op->randomitems = NULL; /* So another spell isn't created for this object */
382 /* without this, value is all screwed up */
383 op->value = op->arch->clone.value*op->inv->value;
384 }
385
386 if (QUERY_FLAG(op, FLAG_MONSTER)) {
387 if (op->stats.hp > op->stats.maxhp)
388 LOG(llevDebug, "Monster %s has hp set higher than maxhp (%d>%d)\n", op->name, op->stats.hp, op->stats.maxhp);
389 }
390 if ((QUERY_FLAG(op, FLAG_GENERATOR) && QUERY_FLAG(op, FLAG_CONTENT_ON_GEN))
391 || op->type == CREATOR
392 || op->type == CONVERTER) {
393 /* Object will duplicate it's content as part of the
394 * generation process. To do this, we must flag inventory
395 * so it remains unevaluated concerning the randomitems and
396 * the living (a demonlord shouldn't cast from inside generator!)
397 */
398 object_set_flag_inv(op, FLAG_IS_A_TEMPLATE);
399 }
400
401 /* if the item is identified, ensure we got the correct face */
402 if (QUERY_FLAG(op, FLAG_IDENTIFIED))
403 object_give_identified_properties(op);
404
405 /* Here we'll handle custom monsters. In order to handle them correctly, especially in the fix_object
406 * method, we'll create a new temporary archetype containing defined values.
407 * Of course this doesn't apply when loading archetypes or artifacts.
408 */
409 if (arch_init == 0
410 && artifact_init == 0
411 && QUERY_FLAG(op, FLAG_MONSTER)
412 && op->arch
413 && !object_can_merge(op, &op->arch->clone)) {
414 archetype *temp = get_archetype_struct();
415 temp->reference_count++;
416 temp->name = add_string(op->arch->name);
417 temp->tail_x = op->arch->tail_x;
418 temp->tail_y = op->arch->tail_y;
419 object_copy(op, &temp->clone);
420 temp->clone.inv = NULL;
421 temp->clone.env = NULL;
422 temp->clone.x = 0;
423 temp->clone.y = 0;
424 temp->clone.map = NULL;
425 if (FABS(temp->clone.speed) > MIN_ACTIVE_SPEED) {
426 /* Clone has a speed, so need to clear that because it isn't on a map.
427 * But we need to keep the value, because otherwise the customized object
428 * will have no speed (fix_player() will use the 0 value). So set it
429 * to zero, call object_update_speed() to remove it from active list, then
430 * set its speed back to the original.
431 */
432 temp->clone.speed = 0;
433 object_update_speed(&temp->clone);
434 temp->clone.speed = op->speed;
435 }
436
437 temp->more = op->arch->more;
438 op->arch = temp;
439 /* LOG(llevDebug, "created temporary archetype for %s at %d,%d\n", op->name, op->x, op->y); */
440 }
441 }
442
443 /**
444 * This extracts the key/value from the yytext field -
445 * calls object_set_value() to actually set the value.
446 * Function basically has to find spaces, strip out extra,
447 * etc. strchr doesn't work as good because could also
448 * be tabs.
449 *
450 * @param op
451 * object in which to insert the value.
452 */
453 static void add_key_value(object *op) {
454 char *key = NULL;
455 char *value = NULL;
456 char *cp;
457 char *end;
458
459 /* First, skip over leading whitespace. */
460 for (cp = yytext; isspace(*cp); cp++) {
461 ;
462 }
463
464 key = cp;
465
466 /* Now look for the end of the key/field name. */
467 for (; !isspace(*cp); cp++) {
468 if (*cp == '\0') {
469 /* Oops, ran out of string! Set the key with an empty value. */
470 object_set_value(op, key, NULL, TRUE);
471 return;
472 }
473 }
474
475 if (*cp == '\0') {
476 object_set_value(op, key, NULL, TRUE);
477 return;
478 }
479
480 /* Chop off the key, and start at the next character. */
481 *cp = '\0';
482 cp++;
483 if (*cp == '\0') {
484 /* Was followed by one space? */
485 object_set_value(op, key, NULL, TRUE);
486 return;
487 }
488
489 /* Now looking for the value. Skip over whitespace. */
490 for (; isspace(*cp); cp++) {
491 if (*cp == '\0') {
492 /* Guess not. */
493 object_set_value(op, key, NULL, TRUE);
494 return;
495 }
496 }
497
498 value = cp;
499
500 /* Got last character before null and strip
501 * off tailing whitespace
502 */
503 for (end = value+(strlen(cp)-1); isspace(*end); end--) {
504 if (end == value) {
505 /* *blink blink* Still no value? */
506 object_set_value(op, key, NULL, TRUE);
507 return;
508 }
509 *end = '\0';
510 }
511 object_set_value(op, key, value, TRUE);
512 }
513
514 /**
515 * Handles the different move types an object can have.
516 *
517 * @param mt
518 * field for which we are computing the value, will be set to the result of parsing.
519 * @param params
520 * string containing the definition of the move type to parse.
521 * @param prefix
522 * string to be displayed in case the move type is invalid, must not be NULL.
523 */
524 static void set_move(MoveType *mt, char *params, const char *prefix) {
525 char *str;
526 int i, negate;
527
528 if (isdigit(*params)) {
529 *mt = atoi(params);
530 } else {
531 *mt = 0;
532 for (str = strtok(params, " "); str; str = strtok(NULL, " ")) {
533 negate = 0;
534 if (!strcasecmp(str, "all"))
535 *mt |= MOVE_ALL;
536 else {
537 if (*str == '-') {
538 negate = 1;
539 str++;
540 }
541 for (i = 0; move_name[i] != NULL; i++) {
542 if (!strcasecmp(move_name[i], str)) {
543 if (negate) {
544 *mt &= ~(1<<i);
545 } else {
546 *mt |= (1<<i);
547 }
548 break;
549 }
550 }
551 if (move_name[i] == NULL) {
552 /* fly is a special case - covers both fly_low and
553 * fly_high - since it doesn't match to a specific
554 * single bit, have to special case it.
555 */
556 if (!strcasecmp(str, "flying")) {
557 if (negate) {
558 *mt &= ~MOVE_FLYING;
559 } else {
560 *mt |= MOVE_FLYING;
561 }
562 } else {
563 LOG(llevDebug, "common/loader.l: set_move(%s) - unknown move string '%s'\n", prefix, str);
564 }
565 }
566 } /* Else not all move types */
567 } /* for strtok */
568 } /* Else not a numeric value */
569 }
570
571 %}
572
573 S [ \t]+.+
574 WS [ \t]*
575 A .+
576
577 %x MESSAGE
578 %x LORE
579 %x SCRIPT
580
581 /* Don't have to link with -lfl with this */
582 %option noyywrap
583
584 /* need yy_push_state, yy_pop_state */
585 %option stack
586
587 /* those functions are unused, not sure of compatibility with Flex versions. */
588 %option nounput
589 %option noyy_top_state
590 %option noinput
591
592 %%
593
594 %{
595 /* Declare some local variables */
596 int ismore = 0;
597
598 object *op = items[*depth];
599 lex_error = 0;
600
601 %}
602
603 ^msg{WS}$ { BEGIN(MESSAGE); msgbuf[0] = '\0'; msglen = 0; total_msglen = 0;}
604 <MESSAGE>^endmsg{WS}$ { BEGIN(INITIAL);
605 object_set_msg(op, msgbuf);
606 /* Just print a warning so we can be reasonably safe
607 * about not overflowing the buffer.
608 */
609 if (total_msglen > (HUGE_BUF / 2))
610 LOG(llevDebug,
611 "warning: msg in '%s' on %s is very long (%lu "
612 "characters)\n",
613 op->name,
614 op->map != NULL ? op->map->path : "no map",
615 (unsigned long)total_msglen);
616 }
617 <MESSAGE>.* { safe_strcat(msgbuf, yytext, &msglen, HUGE_BUF);
618 safe_strcat(msgbuf, "\n", &msglen, HUGE_BUF);
619 total_msglen += strlen(yytext)+1;
620 }
621
622 ^lore{WS}$ { BEGIN(LORE); lorebuf[0] = '\0'; }
623 <LORE>^endlore{WS}$ { BEGIN(INITIAL);
624 op->lore = add_string(lorebuf);
625 /* Just print a warning so we can be reasonably safe
626 * about not overflowing the buffer.
627 */
628 if (strlen(op->lore) > (HUGE_BUF/2))
629 LOG(llevDebug, "\n\tWarning lore length > %d (max allowed=%d): %lu\n>%.80s<\n",
630 HUGE_BUF/2, HUGE_BUF, (unsigned long)strlen(op->lore), op->lore);
631 }
632 <LORE>.* { strcat(lorebuf, yytext); strcat(lorebuf, "\n"); }
633
634 ^object{S} {
635 char *yv = yval();
636
637 if (*yv == '\0') {
638 LOG(llevError, "Object lacks name.\n");
639 return LL_IGNORED;
640 }
641 if (seen_object) {
642 LOG(llevError, "An object started before the 'end' of object %s.\n", (op->arch && op->arch->name) ? op->arch->name : "(no name)");
643 }
644 if (!arch_init) {
645 LOG(llevError, "Got object info when not in arch_init (%s)?\n", yv);
646 } else {
647 if (op->arch != NULL)
648 op->arch->name = add_string(yv);
649 op->name = add_string(yv);
650 }
651 seen_object = true;
652 }
653
654 ^name{S} {
655 char *yv = yval();
656
657 if (*yv == '\0')
658 LOG(llevError, "Name without val\n");
659 else
660 FREE_AND_COPY(op->name, yv);
661 }
662 ^name_pl{S} {
663 char *yv = yval();
664
665 if (*yv == '\0')
666 LOG(llevError, "Name without val\n");
667 else
668 FREE_AND_COPY(op->name_pl, yv);
669 }
670 ^anim_suffix{S} {
671 char *yv = yval();
672
673 if (*yv == '\0')
674 LOG(llevError, "Anim suffix without val\n");
675 else
676 FREE_AND_COPY(op->anim_suffix, yv);
677 }
678 ^skill{S} FREE_AND_COPY(op->skill, yval());
679 ^custom_name{S} {
680 char *yv = yval();
681
682 if (*yv == '\0')
683 LOG(llevError, "Custom name without val\n");
684 else
685 FREE_AND_COPY(op->custom_name, yv);
686 }
687 ^race{S} FREE_AND_COPY(op->race, yval());
688 ^slaying{S} FREE_AND_COPY(op->slaying, yval());
689 ^arch{S} {
690 if (op->arch) {
691 /*
692 Here an object must be inserted into another object,
693 during archetypes, artifact or map loading.
694
695 The logic is as follow:
696 - in linemode, we are loading artifacts, so just
697 increase depth, next calls will work on object
698 in inventory, and insertion in previous object done
699 in the "end" part
700 - when not in linemode, two cases:
701 - arch_init is not set, then we are loading a map
702 - arch_init is set, we are loading archetypes,
703 discard the object, it'll be handled in a second pass
704 */
705 object *tmp;
706 char *yv = yval();
707
708 tmp = object_new();
709 tmp->arch = try_find_archetype(yv);
710 if (tmp->arch != NULL)
711 object_copy(&tmp->arch->clone, tmp);
712 else {
713 if (tmp->name)
714 free_string(tmp->name);
715 /* record the name of the broken object */
716 tmp->name = add_string(yv);
717 }
718 strcpy(msgbuf, "");
719 strcpy(lorebuf, "");
720 msglen = 0;
721 total_msglen = 0;
722 (*depth)++;
723 items[*depth] = tmp;
724 if (linemode == 0) {
725 lex_load(depth, items, maxdepth, map_flags, linemode);
726 (*depth)--;
727 if (tmp->arch && (arch_init == 0)) {
728 /* Map loading, object into another object*/
729 object_insert_in_ob(tmp, op);
730 } else {
731 /* Archetypes loading or invalid object in a map */
732 if (arch_init == 0)
733 LOG(llevDebug, "Discarding object without arch: %s\n", tmp->name ? tmp->name : "(null)");
734 object_free_drop_inventory(tmp);
735 }
736 }
737 } else {
738 /* Here we are loading an object in a map, on a spot, not
739 * in another object's inventory */
740 char *yv = yval();
741
742 op->arch = try_find_archetype(yv);
743 if (op->arch != NULL)
744 object_copy(&op->arch->clone, op);
745 else if (!arch_init) {
746 if (op->name)
747 free_string(op->name);
748 /* record the name of the broken object */
749 op->name = add_string(yv);
750 }
751 }
752 }
753 ^artifact{S} {
754 const char *yv = yval();
755 const artifact *art = find_artifact(op, yv);
756 if (art == NULL) {
757 LOG(llevError, "can't find artifact %s [%d]\n for loading", yv, op->type);
758 } else {
759 give_artifact_abilities(op, art->item);
760 }
761 }
762
763 ^other_arch{S} op->other_arch = try_find_archetype(yval());
764 ^animation{S} {
765 if (strcmp (yval(), "NONE") == 0) {
766 op->animation = NULL;
767 CLEAR_FLAG (op, FLAG_ANIMATE);
768 } else {
769 op->animation = find_animation (yval());
770 SET_FLAG (op, FLAG_ANIMATE);
771 }
772 }
773
774 ^more{WS}$ { /* We need to record that this is a multipart object,
775 * so the calling function can glue things back together
776 */
777 ismore = 1;
778 }
779
780 ^end{WS}$ {
781 seen_object = false;
782 check_loaded_object(op);
783 if (linemode) {
784 /* Linemode is only set for artifact loading. */
785 if ((*depth) > 0) {
786 /* Object we finished is in another object's inventory */
787 object_insert_in_ob(items[*depth], items[(*depth)-1]);
788 }
789 return LL_NORMAL;
790 }
791 if (ismore)
792 return LL_MORE;
793 else
794 return LL_NORMAL;
795 }
796 ^last_heal{S} op->last_heal = IVAL;
797 ^last_sp{S} op->last_sp = IVAL;
798 ^last_grace{S} op->last_grace = IVAL;
799 ^last_eat{S} op->last_eat = IVAL;
800 ^speed{S} {
801 op->speed = FVAL;
802 if (!(map_flags&MAP_STYLE)) {
803 if (op->speed < 0) {
804 op->speed_left = op->speed_left-RANDOM()%100/100.0;
805 op->speed = -op->speed; // Make this always positive
806 }
807 object_update_speed(op);
808 }
809 }
810 ^speed_left{S} op->speed_left = FVAL;
811
812 ^weapon_speed_left{S} op->weapon_speed_left = FVAL;
813 ^weapon_speed{S} op->weapon_speed = FVAL;
814
815 ^slow_move{S} {
816 op->move_slow |= MOVE_WALK;
817 op->move_slow_penalty = FVAL;
818 }
819 ^title{S} {
820 char *y = yval();
821
822 if (*y == '\0')
823 LOG(llevError, "Title without value.\n");
824 else
825 FREE_AND_COPY(op->title, y);
826 }
827
828 ^face{S} {
829 const char *name = yval();
830 op->face = find_face(yval(), NULL);
831 if (op->face == NULL)
832 LOG(llevError, "couldn't find face %s for %s\n", name, op->arch ? op->arch->name : op->name);
833 }
834 ^str{S} op->stats.Str = IVAL;
835 ^dex{S} op->stats.Dex = IVAL;
836 ^con{S} op->stats.Con = IVAL;
837 ^wis{S} op->stats.Wis = IVAL;
838 ^cha{S} op->stats.Cha = IVAL;
839 ^int{S} op->stats.Int = IVAL;
840 ^pow{S} op->stats.Pow = IVAL;
841 ^hp{S} op->stats.hp = IVAL;
842 ^maxhp{S} op->stats.maxhp = IVAL;
843 ^sp{S} op->stats.sp = IVAL;
844 ^maxsp{S} op->stats.maxsp = IVAL;
845 ^grace{S} op->stats.grace = IVAL;
846 ^maxgrace{S} op->stats.maxgrace = IVAL;
847 ^exp{S} op->stats.exp = atoll(yval());
848 ^total_exp{S} op->total_exp = atoll(yval());
849 ^perm_exp{S} op->total_exp = (atoll(yval()) * 100 / settings.permanent_exp_ratio);
850 ^food{S} op->stats.food = IVAL;
851 ^dam{S} op->stats.dam = IVAL;
852 ^wc{S} op->stats.wc = IVAL;
853 ^ac{S} op->stats.ac = IVAL;
854 ^x{S} { op->x = IVAL; op->ox= op->x; }
855 ^y{S} { op->y = IVAL; op->oy= op->y; }
856 ^nrof{S} op->nrof= atol(yval());
857 ^level{S} op->level = IVAL;
858 ^direction{S} op->direction = IVAL;
859 ^type{S} op->type = IVAL;
860 ^subtype{S} op->subtype = IVAL;
861 ^material{S} op->material = IVAL;
862 ^materialname{S} {
863 char *yv = yval();
864
865 if (*yv == '\0')
866 LOG(llevError, "Materialname without val\n");
867 else
868 FREE_AND_COPY(op->materialname, yv);
869 }
870
871 ^value{S} op->value = IVAL;
872 ^weight{S} {
873 op->weight = atol(yval());
874 if (op->weight == 0) {
875 SET_FLAG(op, FLAG_NO_PICK);
876 }
877 }
878 ^carrying{S} op->carrying = atol(yval());
879 ^attacktype{S} op->attacktype = IVAL;
880 ^path_attuned{S} op->path_attuned = IVAL;
881 ^path_repelled{S} op->path_repelled = IVAL;
882 ^path_denied{S} op->path_denied = IVAL;
883 ^invisible{S} op->invisible = IVAL;
884 ^magic{S} op->magic = IVAL;
885 ^state{S} op->state = IVAL;
886 ^alive{S} SET_OR_CLEAR_FLAG(op, FLAG_ALIVE, IVAL);
887 ^applied{S} SET_OR_CLEAR_FLAG(op, FLAG_APPLIED, IVAL);
888 ^unpaid{S} SET_OR_CLEAR_FLAG(op, FLAG_UNPAID, IVAL);
889 ^is_animated{S} SET_OR_CLEAR_FLAG(op, FLAG_ANIMATE, IVAL);
890 ^no_pick{S} SET_OR_CLEAR_FLAG(op, FLAG_NO_PICK, IVAL);
891 ^client_anim_sync{S} SET_OR_CLEAR_FLAG(op, FLAG_CLIENT_ANIM_SYNC, IVAL);
892 ^client_anim_random{S} SET_OR_CLEAR_FLAG(op, FLAG_CLIENT_ANIM_RANDOM, IVAL);
893
894 %{ /* These are the new values */
895 %}
896 ^move_block{S} set_move(&op->move_block, yval(), "block");
897 ^move_allow{S} set_move(&op->move_allow, yval(), "allow");
898 ^move_type{S} set_move(&op->move_type, yval(), "type");
899 ^move_on{S} set_move(&op->move_on, yval(), "on");
900 ^move_off{S} set_move(&op->move_off, yval(), "off");
901 ^move_slow{S} set_move(&op->move_slow, yval(), "slow");
902 ^move_slow_penalty{S} op->move_slow_penalty = FVAL;
903
904
905 ^monster{S} SET_OR_CLEAR_FLAG(op, FLAG_MONSTER, IVAL);
906 ^neutral{S} SET_OR_CLEAR_FLAG(op, FLAG_NEUTRAL, IVAL);
907 ^no_attack{S} SET_OR_CLEAR_FLAG(op, FLAG_NO_ATTACK, IVAL);
908 ^no_damage{S} SET_OR_CLEAR_FLAG(op, FLAG_NO_DAMAGE, IVAL);
909 ^friendly{S} {
910 if (IVAL) {
911 SET_FLAG(op, FLAG_FRIENDLY);
912 if (op->type != PLAYER) {
913 LOG(llevDebug, " Adding friendly object %s.\n", op->name);
914 add_friendly_object(op);
915 }
916 }
917 else
918 CLEAR_FLAG(op, FLAG_FRIENDLY);
919 }
920 ^generator{S} SET_OR_CLEAR_FLAG(op, FLAG_GENERATOR, IVAL);
921 ^use_content_on_gen{S} SET_OR_CLEAR_FLAG (op, FLAG_CONTENT_ON_GEN, IVAL);
922 ^is_thrown{S} SET_OR_CLEAR_FLAG(op, FLAG_IS_THROWN, IVAL);
923 ^auto_apply{S} SET_OR_CLEAR_FLAG(op, FLAG_AUTO_APPLY, IVAL);
924 ^treasure{S} SET_OR_CLEAR_FLAG(op, FLAG_TREASURE, IVAL);
925 ^see_invisible{S} SET_OR_CLEAR_FLAG(op, FLAG_SEE_INVISIBLE, IVAL);
926 ^can_roll{S} SET_OR_CLEAR_FLAG(op, FLAG_CAN_ROLL, IVAL);
927 ^overlay_floor{S} SET_OR_CLEAR_FLAG(op, FLAG_OVERLAY_FLOOR, IVAL);
928 ^is_turnable{S} SET_OR_CLEAR_FLAG(op, FLAG_IS_TURNABLE, IVAL);
929 ^is_used_up{S} SET_OR_CLEAR_FLAG(op, FLAG_IS_USED_UP, IVAL);
930 ^identified{S} {
931 if (IVAL) {
932 SET_FLAG(op, FLAG_IDENTIFIED);
933 CLEAR_FLAG(op, FLAG_KNOWN_MAGICAL);
934 }
935 else
936 CLEAR_FLAG(op, FLAG_IDENTIFIED);
937 }
938 ^reflecting{S} SET_OR_CLEAR_FLAG(op, FLAG_REFLECTING, IVAL);
939 ^changing{S} SET_OR_CLEAR_FLAG(op, FLAG_CHANGING, IVAL);
940 ^splitting{S} SET_OR_CLEAR_FLAG(op, FLAG_SPLITTING, IVAL);
941 ^hitback{S} SET_OR_CLEAR_FLAG(op, FLAG_HITBACK, IVAL);
942 ^startequip{S} SET_OR_CLEAR_FLAG(op, FLAG_STARTEQUIP, IVAL);
943 ^blocksview{S} SET_OR_CLEAR_FLAG(op, FLAG_BLOCKSVIEW, IVAL);
944 ^editor_folder{S} { /* This field is used by Gridarta, so it's not an error. */ }
945 ^undead{S} SET_OR_CLEAR_FLAG(op, FLAG_UNDEAD, IVAL);
946 ^scared{S} SET_OR_CLEAR_FLAG(op, FLAG_SCARED, IVAL);
947 ^unaggressive{S} SET_OR_CLEAR_FLAG(op, FLAG_UNAGGRESSIVE, IVAL);
948 ^reflect_missile{S} SET_OR_CLEAR_FLAG(op, FLAG_REFL_MISSILE, IVAL);
949 ^reflect_spell{S} SET_OR_CLEAR_FLAG(op, FLAG_REFL_SPELL, IVAL);
950 ^no_magic{S} SET_OR_CLEAR_FLAG(op, FLAG_NO_MAGIC, IVAL);
951 ^wiz{S} {
952 if (IVAL) {
953 SET_FLAG(op, FLAG_WIZ);
954 SET_FLAG(op, FLAG_WAS_WIZ);
955 SET_FLAG(op, FLAG_WIZPASS);
956 SET_FLAG(op, FLAG_WIZCAST);
957 } else {
958 CLEAR_FLAG(op, FLAG_WIZ);
959 CLEAR_FLAG(op, FLAG_WIZPASS);
960 CLEAR_FLAG(op, FLAG_WIZCAST);
961 }
962 }
963 ^was_wiz{S} SET_OR_CLEAR_FLAG(op, FLAG_WAS_WIZ, IVAL);
964 ^no_fix_player{S} SET_OR_CLEAR_FLAG(op, FLAG_NO_FIX_PLAYER, IVAL);
965 ^is_lightable{S} SET_OR_CLEAR_FLAG(op, FLAG_IS_LIGHTABLE, IVAL);
966 ^tear_down{S} SET_OR_CLEAR_FLAG(op, FLAG_TEAR_DOWN, IVAL);
967 ^luck{S} op->stats.luck = IVAL;
968 ^run_away{S} op->run_away = IVAL;
969 ^pick_up{S} op->pick_up = IVAL;
970 ^item_power{S} op->item_power = IVAL;
971 ^gen_sp_armour{S} op->gen_sp_armour = IVAL;
972 ^anim_speed{S} op->anim_speed = IVAL;
973 ^container{S} op->weight_limit = IVAL;
974 ^no_drop{S} SET_OR_CLEAR_FLAG(op, FLAG_NO_DROP, IVAL);
975 ^will_apply{S} op->will_apply = IVAL;
976 ^random_movement{S} SET_OR_CLEAR_FLAG(op, FLAG_RANDOM_MOVE, IVAL);
977 ^can_use_shield{S} SET_OR_CLEAR_FLAG(op, FLAG_USE_SHIELD, IVAL);
978 ^can_cast_spell{S} SET_OR_CLEAR_FLAG(op, FLAG_CAST_SPELL, IVAL);
979 ^can_use_scroll{S} SET_OR_CLEAR_FLAG(op, FLAG_USE_SCROLL, IVAL);
980 ^can_use_range{S} SET_OR_CLEAR_FLAG(op, FLAG_USE_RANGE, IVAL);
981 ^can_use_bow{S} SET_OR_CLEAR_FLAG(op, FLAG_USE_BOW, IVAL);
982 ^can_use_armour{S} SET_OR_CLEAR_FLAG(op, FLAG_USE_ARMOUR, IVAL);
983 ^can_use_weapon{S} SET_OR_CLEAR_FLAG(op, FLAG_USE_WEAPON, IVAL);
984 ^can_use_ring{S} SET_OR_CLEAR_FLAG(op, FLAG_USE_RING, IVAL);
985 ^has_ready_bow{S} SET_OR_CLEAR_FLAG(op, FLAG_READY_BOW, IVAL);
986 ^xrays{S} SET_OR_CLEAR_FLAG(op, FLAG_XRAYS, IVAL);
987 ^is_floor{S} SET_OR_CLEAR_FLAG(op, FLAG_IS_FLOOR, IVAL);
988 ^lifesave{S} SET_OR_CLEAR_FLAG(op, FLAG_LIFESAVE, IVAL);
989 ^no_strength{S} SET_OR_CLEAR_FLAG(op, FLAG_NO_STRENGTH, IVAL);
990 ^sleep{S} SET_OR_CLEAR_FLAG(op, FLAG_SLEEP, IVAL);
991 ^stand_still{S} SET_OR_CLEAR_FLAG(op, FLAG_STAND_STILL, IVAL);
992 ^only_attack{S} SET_OR_CLEAR_FLAG(op, FLAG_ONLY_ATTACK, IVAL);
993
994 ^activate_on_push{S} SET_OR_CLEAR_FLAG(op, FLAG_ACTIVATE_ON_PUSH, IVAL);
995 ^activate_on_release{S} SET_OR_CLEAR_FLAG(op, FLAG_ACTIVATE_ON_RELEASE, IVAL);
996
997 /* Start of various attacktypes */
998 ^resist_physical{S} SET_RESIST(op, ATNR_PHYSICAL, IVAL);
999 ^resist_magic{S} SET_RESIST(op, ATNR_MAGIC, IVAL);
1000 ^resist_fire{S} SET_RESIST(op, ATNR_FIRE, IVAL);
1001 ^resist_electricity{S} SET_RESIST(op, ATNR_ELECTRICITY, IVAL);
1002 ^resist_cold{S} SET_RESIST(op, ATNR_COLD, IVAL);
1003 ^resist_confusion{S} SET_RESIST(op, ATNR_CONFUSION, IVAL);
1004 ^resist_acid{S} SET_RESIST(op, ATNR_ACID, IVAL);
1005 ^resist_drain{S} SET_RESIST(op, ATNR_DRAIN, IVAL);
1006 ^resist_weaponmagic{S} SET_RESIST(op, ATNR_WEAPONMAGIC, IVAL);
1007 ^resist_ghosthit{S} SET_RESIST(op, ATNR_GHOSTHIT, IVAL);
1008 ^resist_poison{S} SET_RESIST(op, ATNR_POISON, IVAL);
1009 ^resist_slow{S} SET_RESIST(op, ATNR_SLOW, IVAL);
1010 ^resist_paralyze{S} SET_RESIST(op, ATNR_PARALYZE, IVAL);
1011 ^resist_turn_undead{S} SET_RESIST(op, ATNR_TURN_UNDEAD, IVAL);
1012 ^resist_fear{S} SET_RESIST(op, ATNR_FEAR, IVAL);
1013 ^resist_cancellation{S} SET_RESIST(op, ATNR_CANCELLATION, IVAL);
1014 ^resist_deplete{S} SET_RESIST(op, ATNR_DEPLETE, IVAL);
1015 ^resist_death{S} SET_RESIST(op, ATNR_DEATH, IVAL);
1016 ^resist_chaos{S} SET_RESIST(op, ATNR_CHAOS, IVAL);
1017 ^resist_counterspell{S} SET_RESIST(op, ATNR_COUNTERSPELL, IVAL);
1018 ^resist_godpower{S} SET_RESIST(op, ATNR_GODPOWER, IVAL);
1019 ^resist_holyword{S} SET_RESIST(op, ATNR_HOLYWORD, IVAL);
1020 ^resist_blind{S} SET_RESIST(op, ATNR_BLIND, IVAL);
1021 ^resist_internal{S} SET_RESIST(op, ATNR_INTERNAL, IVAL);
1022 ^resist_life_stealing{S} SET_RESIST(op, ATNR_LIFE_STEALING, IVAL);
1023 ^resist_disease{S} SET_RESIST(op, ATNR_DISEASE, IVAL);
1024 ^attack_movement{S} op->attack_movement = IVAL;
1025 ^move_state{S} op->move_status = IVAL;
1026 ^confused{S} SET_OR_CLEAR_FLAG(op, FLAG_CONFUSED, IVAL);
1027 ^stealth{S} SET_OR_CLEAR_FLAG(op, FLAG_STEALTH, IVAL);
1028 ^connected{S} add_button_link(op, op->map, IVAL);
1029 ^cursed{S} SET_OR_CLEAR_FLAG(op, FLAG_CURSED, IVAL);
1030 ^damned{S} SET_OR_CLEAR_FLAG(op, FLAG_DAMNED, IVAL);
1031 ^blessed{S} SET_OR_CLEAR_FLAG(op, FLAG_BLESSED, IVAL);
1032 ^see_anywhere{S} SET_OR_CLEAR_FLAG(op, FLAG_SEE_ANYWHERE, IVAL);
1033 ^known_magical{S} SET_OR_CLEAR_FLAG(op, FLAG_KNOWN_MAGICAL, IVAL);
1034 ^known_cursed{S} SET_OR_CLEAR_FLAG(op, FLAG_KNOWN_CURSED, IVAL);
1035 ^known_blessed{S} SET_OR_CLEAR_FLAG(op, FLAG_KNOWN_BLESSED, IVAL);
1036 ^can_use_skill{S} SET_OR_CLEAR_FLAG(op, FLAG_CAN_USE_SKILL, IVAL);
1037 ^been_applied{S} SET_OR_CLEAR_FLAG(op, FLAG_BEEN_APPLIED, IVAL);
1038 ^has_ready_scroll{S} SET_OR_CLEAR_FLAG(op, FLAG_READY_SCROLL, IVAL);
1039 ^expmul{S} op->expmul = FVAL;
1040 ^unique{S} SET_OR_CLEAR_FLAG(op, FLAG_UNIQUE, IVAL);
1041 ^make_invisible{S} SET_OR_CLEAR_FLAG(op, FLAG_MAKE_INVIS, IVAL);
1042 ^inv_locked{S} SET_OR_CLEAR_FLAG(op, FLAG_INV_LOCKED, IVAL);
1043 ^is_wooded{S} SET_OR_CLEAR_FLAG(op, FLAG_IS_WOODED, IVAL);
1044 ^is_hilly{S} SET_OR_CLEAR_FLAG(op, FLAG_IS_HILLY, IVAL);
1045 ^is_water{S} SET_OR_CLEAR_FLAG(op, FLAG_IS_WATER, IVAL);
1046 ^has_ready_skill{S} SET_OR_CLEAR_FLAG(op, FLAG_READY_SKILL, IVAL);
1047 ^has_ready_weapon{S} SET_OR_CLEAR_FLAG(op, FLAG_READY_WEAPON, IVAL);
1048 ^no_skill_ident{S} SET_OR_CLEAR_FLAG(op, FLAG_NO_SKILL_IDENT, IVAL);
1049 ^glow_radius{S} op->glow_radius = IVAL;
1050 ^is_blind{S} SET_OR_CLEAR_FLAG(op, FLAG_BLIND, IVAL);
1051 ^can_see_in_dark{S} SET_OR_CLEAR_FLAG(op, FLAG_SEE_IN_DARK, IVAL);
1052 ^is_cauldron{S} SET_OR_CLEAR_FLAG(op, FLAG_IS_CAULDRON, IVAL);
1053 ^randomitems{S} op->randomitems = find_treasurelist(yval());
1054 ^no_steal{S} SET_OR_CLEAR_FLAG(op, FLAG_NO_STEAL, IVAL);
1055 ^one_hit{S} SET_OR_CLEAR_FLAG(op, FLAG_ONE_HIT, IVAL);
1056 ^berserk{S} SET_OR_CLEAR_FLAG(op, FLAG_BERSERK, IVAL);
1057
1058 ^can_knockback{S} { /* Some archetypes have these values in them */ }
1059 ^can_parry{S} { /* Probably the pupland archetypes - I imagined */ }
1060 ^can_impale{S} { /* That these are for the new combat code */ }
1061 ^can_cut{S} { /* just ignore for now */ }
1062 ^can_dam_armour{S} { }
1063 ^weapontype{S} op->weapontype = IVAL;
1064 ^casting_time{S} op->casting_time = FVAL;
1065 ^smoothlevel{S} op->smoothlevel = IVAL;
1066 ^map_layer{S} {
1067 if (IVAL)
1068 op->map_layer = IVAL;
1069 else {
1070 int i;
1071 char *cp = yval();
1072
1073 for (i = 0; i < MAP_LAYERS; i++) {
1074 if (!strcasecmp(cp, map_layer_name[i])) {
1075 op->map_layer = i;
1076 break;
1077 }
1078 }
1079 if (i == MAP_LAYERS) {
1080 LOG(llevError, "Invalid map_layer name found: %s\n", cp);
1081 }
1082 }
1083 }
1084 ^client_type{S} op->client_type = IVAL;
1085 ^body_{A} set_body_info(op, yytext);
1086 ^duration{S} op->duration = IVAL;
1087 ^range{S} op->range = IVAL;
1088 ^range_modifier{S} op->range_modifier = IVAL;
1089 ^dam_modifier{S} op->dam_modifier = IVAL;
1090 ^duration_modifier{S} op->duration_modifier = IVAL;
1091 ^is_buildable{S} SET_OR_CLEAR_FLAG(op, FLAG_IS_BUILDABLE, IVAL);
1092 ^sound_chance{S} op->sound_chance = IVAL;
1093 ^paralyzed{S} SET_OR_CLEAR_FLAG(op, FLAG_PARALYZED, IVAL);
1094
1095 <*>(^{WS}$)|\n { /* ignore empty lines, newlines we don't do above */ }
1096 #.*\n { }
1097
1098 <<EOF>> { /* If we got an error, return the error. Otherwise, return that we got EOF */
1099 if (lex_error != 0)
1100 return lex_error;
1101 else
1102 return LL_EOF;
1103 }
1104 .* { add_key_value(op); }
1105 %%
1106
1107 /**
1108 * Returns the next token for lex.
1109 * Our save file syntax is very simple, so we can use a very simple
1110 * processing mechanism here instead using something like bison
1111 * This skips over the space and returns the value, or "" if no value
1112 * is found. Modified 4/26/2000 to also strip spaces at end of
1113 * line
1114 */
1115 static char *yval(void)
1116 {
1117 static char em[] = "";
1118 char *cp, *end;
1119
1120 /* First skip over start of line, like animation or name */
1121 for (cp = yytext; *cp != ' '; cp++) {
1122 if (*cp == '\0') {
1123 return em;
1124 }
1125 }
1126
1127 /* Skip over whitespace */
1128 for (; *cp == ' '; cp++) {
1129 if (*cp == '\0') {
1130 return em;
1131 }
1132 }
1133 /* Got last character before null and strip
1134 * off tailing whitespace
1135 */
1136 for (end = cp+strlen(cp)-1; *end == ' '; end--) {
1137 if (end == cp)
1138 return em;
1139 *end = '\0';
1140 }
1141 return cp;
1142 }
1143
1144 /**
1145 * Loads an object from the given file-pointer.
1146 * Variables will be read and parsed and patched into the object
1147 * until the string "end" is reached, or the end of the file.
1148 *
1149 * @param fp
1150 * file pointer from which to read.
1151 * @param op
1152 * where to read the data.
1153 * @param bufstate
1154 * used to determine various file attributes:
1155 * @li LO_REPATE (0): We are reading from the same buffer as the last call.
1156 * @li LO_LINEMODE (1): file that is being read from is multi purpose (ie, other functions
1157 * will also be reading from this (treasure file, artifacts.)
1158 * @li LO_NEWFILE (2): This is the first read from a particular file, so the buffers should be reset.
1159 * @li LO_NOREAD (3): Reset the buffers, but don't read from it. (op can be null)
1160 * @param map_flags
1161 * combination of @ref MAP_xxx flags, though only MAP_STYLE is used.
1162 * @return
1163 * @li LL_NORMAL if object was read.
1164 * @li LL_EOF if an error occured.
1165 * @li LL_MORE if this is a multipart object.
1166 */
1167 int load_object(FILE *fp, object *op, int bufstate, int map_flags) {
1168 int retval;
1169 char inbuf[VERY_BIG_BUF];
1170 #define MAXDEPTH 10
1171 object *items[MAXDEPTH];
1172 int depth = 0;
1173
1174 items[0] = op,
1175 strcpy(msgbuf, "");
1176 msglen = 0;
1177 total_msglen = 0;
1178 strcpy(lorebuf, "");
1179 if (bufstate == LO_NEWFILE || bufstate == LO_NOREAD) {
1180 /* LOG(llevDebug, "Switching lex buffers\n");*/
1181 yy_delete_buffer(YY_CURRENT_BUFFER);
1182 yy_switch_to_buffer(yy_create_buffer(fp, YY_BUF_SIZE));
1183 if (bufstate == LO_NOREAD)
1184 return LL_NORMAL;
1185 } else if (bufstate == LO_LINEMODE) {
1186 YY_BUFFER_STATE yybufstate;
1187 yy_delete_buffer(YY_CURRENT_BUFFER);
1188 while (fgets(inbuf, VERY_BIG_BUF-3, fp)) {
1189 yybufstate = yy_scan_string(inbuf);
1190 retval = lex_load(&depth, items, MAXDEPTH, map_flags, 1);
1191 yy_delete_buffer(yybufstate);
1192 if (retval == LL_NORMAL) {
1193 if (depth == 0)
1194 return retval;
1195 else
1196 depth--;
1197 }
1198 }
1199 LOG(llevDebug, "Got eof while scanning strings\n");
1200 return LL_EOF;
1201 }
1202
1203 retval = lex_load(&depth, items, MAXDEPTH, map_flags, 0);
1204
1205 /* LOG(llevDebug, " load completed, object=%s\n", op->name);*/
1206 return retval;
1207 }
1208
1209 /**
1210 * This takes a buffer, scans it for variables, and sets those variables
1211 * as appropriate in op.
1212 *
1213 * This function appears to be used in only 2 places - in crossedit to
1214 * override values and in c_wiz to mutate values.
1215 *
1216 * @param op
1217 * object to alter.
1218 * @param buf
1219 * modifications to apply.
1220 * @return
1221 * ?
1222 * @todo
1223 * document return value.
1224 */
1225 int set_variable(object *op, const char *buf) {
1226 YY_BUFFER_STATE yybufstate, yycurbuf = YY_CURRENT_BUFFER;
1227 int retval, depth;
1228 object *items[MAXDEPTH];
1229
1230 strcpy(msgbuf, "");
1231 msglen = 0;
1232 total_msglen = 0;
1233 strcpy(lorebuf, "");
1234 items[0] = op;
1235 depth = 0;
1236 yy_push_state(INITIAL);
1237 yybufstate = yy_scan_string(buf);
1238 retval = lex_load(&depth, items, MAXDEPTH, 0, 0);
1239 yy_switch_to_buffer(yycurbuf);
1240 yy_delete_buffer(yybufstate);
1241 yy_pop_state();
1242 return retval;
1243 }
1244
1245 /* Start of C code */
1246
1247 /**
1248 * Frees all memory allocated by the loader.
1249 */
1250 void free_loader(void) {
1251 yy_delete_buffer(YY_CURRENT_BUFFER);
1252
1253 /* Comment out this yylex_destroy(), as it results in link errors
1254 * on linux
1255 */
1256 /* yylex_destroy();*/
1257 }