ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/loader.l
Revision: 1.1
Committed: Fri Feb 3 07:11:36 2006 UTC (18 years, 3 months ago) by root
Branch: MAIN
Branch point for: UPSTREAM
Log Message:
Initial revision

File Contents

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