1 | %{ |
1 | %{ |
2 | /* |
2 | /* |
3 | * static char *rcsid_object_c = |
3 | * static char *rcsid_object_c = |
4 | * "$Id: loader.l,v 1.1.1.2 2006/02/22 18:01:20 elmex Exp $"; |
4 | * "$Id: loader.l,v 1.13 2006/08/28 14:05:23 root Exp $"; |
5 | */ |
5 | */ |
6 | |
6 | |
7 | /* |
7 | /* |
8 | CrossFire, A Multiplayer game for X-windows |
8 | CrossFire, A Multiplayer game for X-windows |
9 | |
9 | |
… | |
… | |
35 | #include <global.h> |
35 | #include <global.h> |
36 | #include <loader.h> |
36 | #include <loader.h> |
37 | #include <newserver.h> |
37 | #include <newserver.h> |
38 | #include <sproto.h> |
38 | #include <sproto.h> |
39 | |
39 | |
40 | #define YY_DECL int lex_load(object *op, int map_flags) |
40 | #define YY_DECL int lex_load(object *op, object_thawer &thawer, int map_flags) |
41 | |
41 | |
42 | static char *yval(); |
42 | static char *yval(); |
43 | |
43 | |
44 | static int lex_error; |
44 | static int lex_error; |
45 | static char msgbuf[HUGE_BUF]; |
45 | static char msgbuf[65536]; |
46 | static char lorebuf[HUGE_BUF]; |
46 | static char lorebuf[65536]; |
47 | |
47 | |
48 | /* Maps the MOVE_* values to names */ |
48 | /* Maps the MOVE_* values to names */ |
49 | static const char *const move_name[] = {"walk", "fly_low", "fly_high", "swim", "boat", |
49 | static const char *const move_name[] = {"walk", "fly_low", "fly_high", "swim", "boat", |
50 | NULL}; |
50 | NULL}; |
51 | |
51 | |
… | |
… | |
57 | * If you are adding a new spell, you should not modify this - you |
57 | * If you are adding a new spell, you should not modify this - you |
58 | * new spell won't have been used, and thus won't have any legacy object. |
58 | * new spell won't have been used, and thus won't have any legacy object. |
59 | * NULL entries in this table are valid - to denote objects that should |
59 | * NULL entries in this table are valid - to denote objects that should |
60 | * not be updated for whatever reason. |
60 | * not be updated for whatever reason. |
61 | */ |
61 | */ |
62 | const char *const spell_mapping[] = { |
62 | const char *spell_mapping[] = { |
63 | "spell_magic_bullet", /* 0 */ |
63 | "spell_magic_bullet", /* 0 */ |
64 | "spell_small_fireball", /* 1 */ |
64 | "spell_small_fireball", /* 1 */ |
65 | "spell_medium_fireball", /* 2 */ |
65 | "spell_medium_fireball", /* 2 */ |
66 | "spell_large_fireball", /* 3 */ |
66 | "spell_large_fireball", /* 3 */ |
67 | "spell_burning_hands", /* 4 */ |
67 | "spell_burning_hands", /* 4 */ |
… | |
… | |
325 | } |
325 | } |
326 | } |
326 | } |
327 | LOG(llevError,"set_body_info called with bogus params: %s\n", params); |
327 | LOG(llevError,"set_body_info called with bogus params: %s\n", params); |
328 | } |
328 | } |
329 | |
329 | |
|
|
330 | // return a suitable strign describign an objetc in enough detail to find it |
|
|
331 | // used only in check_loaded_object: TODO remove static, move it elsewhere and |
|
|
332 | // use it in more log messages. |
|
|
333 | static char *op_debug_info_ (object *op, char *info) |
|
|
334 | { |
|
|
335 | char info2[256 * 3]; |
|
|
336 | char *p = info; |
|
|
337 | |
|
|
338 | p += snprintf (p, 256, "%d=\"%s%s%s\"", |
|
|
339 | op->count, |
|
|
340 | op->name ? op->name : "(anon)", |
|
|
341 | op->title ? " " : "", |
|
|
342 | op->title ? op->title : ""); |
|
|
343 | |
|
|
344 | if (op->env) |
|
|
345 | p += snprintf (p, 256, "(in %s)", op_debug_info_ (op->env, info2)); |
|
|
346 | |
|
|
347 | if (op->map) |
|
|
348 | p += snprintf (p, 256, "(on %s@%d+%d)", op->map->path, op->x, op->y); |
|
|
349 | |
|
|
350 | return info; |
|
|
351 | } |
|
|
352 | |
|
|
353 | static char *op_debug_info (object *op) |
|
|
354 | { |
|
|
355 | static char info[256 * 3]; |
|
|
356 | |
|
|
357 | return op_debug_info_ (op, info); |
|
|
358 | } |
330 | |
359 | |
331 | /* This function checks the object after it has been loaded (when we |
360 | /* This function checks the object after it has been loaded (when we |
332 | * get the 'end' in the input stream). This function can be used to |
361 | * get the 'end' in the input stream). This function can be used to |
333 | * deal with legacy objects where fields may have changed. It can also be used |
362 | * deal with legacy objects where fields may have changed. It can also be used |
334 | * to check for objects to make sure there are no common errors. |
363 | * to check for objects to make sure there are no common errors. |
… | |
… | |
363 | * really just to catch any errors - program will still run, but |
392 | * really just to catch any errors - program will still run, but |
364 | * not in the ideal fashion. |
393 | * not in the ideal fashion. |
365 | */ |
394 | */ |
366 | if ((op->type == WEAPON || op->type==BOW) && arch_init) { |
395 | if ((op->type == WEAPON || op->type==BOW) && arch_init) { |
367 | if (!op->skill) { |
396 | if (!op->skill) { |
368 | LOG(llevError,"Weapon %s lacks a skill.\n", op->name); |
397 | LOG(llevError,"Weapon %s lacks a skill.\n", op_debug_info (op)); |
369 | } else if ((!strcmp(op->skill,"one handed weapons") && op->body_info[1] != -1) || |
398 | } 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)) { |
399 | (!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", |
400 | LOG(llevError,"weapon %s arm usage does not match skill: %d, %s\n", |
372 | op->name, op->body_info[1], op->skill); |
401 | op_debug_info (op), op->body_info[1], op->skill); |
373 | } |
402 | } |
374 | } |
403 | } |
375 | |
404 | |
376 | /* We changed last_heal to gen_sp_armour, which is what it |
405 | /* We changed last_heal to gen_sp_armour, which is what it |
377 | * really does for many objects. Need to catch any in maps |
406 | * really does for many objects. Need to catch any in maps |
… | |
… | |
382 | (op->type == SHIELD) || (op->type == RING) || |
411 | (op->type == SHIELD) || (op->type == RING) || |
383 | (op->type == BOOTS) || (op->type == GLOVES) || |
412 | (op->type == BOOTS) || (op->type == GLOVES) || |
384 | (op->type == AMULET ) || (op->type == GIRDLE) || |
413 | (op->type == AMULET ) || (op->type == GIRDLE) || |
385 | (op->type == BRACERS ) || (op->type == CLOAK)) { |
414 | (op->type == BRACERS ) || (op->type == CLOAK)) { |
386 | if (op->last_heal) { |
415 | if (op->last_heal) { |
387 | LOG(llevDebug,"Object %s still has last_heal set, not gen_sp_armour\n", |
416 | LOG(llevDebug,"Object %s still has last_heal set, not gen_sp_armour\n", op_debug_info (op)); |
388 | op->name?op->name:"NULL"); |
|
|
389 | op->gen_sp_armour = op->last_heal; |
417 | op->gen_sp_armour = op->last_heal; |
390 | op->last_heal = 0; |
418 | op->last_heal = 0; |
391 | } |
419 | } |
392 | if (editor) ip =0; |
420 | if (editor) ip =0; |
393 | else ip = calc_item_power(op, 0); |
421 | else ip = calc_item_power(op, 0); |
394 | /* Legacy objects from before item power was in the game */ |
422 | /* Legacy objects from before item power was in the game */ |
395 | if (!op->item_power && ip) { |
423 | if (!op->item_power && ip) { |
396 | if (ip > 3) { |
424 | if (ip > 3) { |
397 | LOG(llevDebug,"Object %s had no item power, using %d\n", |
425 | LOG(llevDebug,"Object %s had no item power, using %d\n", op_debug_info (op), ip); |
398 | op->name?op->name:"NULL", ip); |
|
|
399 | } |
426 | } |
400 | op->item_power = ip; |
427 | op->item_power = ip; |
401 | } |
428 | } |
402 | /* Check for possibly bogus values. Has to meet both these criteria - |
429 | /* Check for possibly bogus values. Has to meet both these criteria - |
403 | * something that has item_power 1 is probably just fine if our calculated |
430 | * something that has item_power 1 is probably just fine if our calculated |
… | |
… | |
405 | * similarly, it item_power is 0, the first check will always pass, |
432 | * similarly, it item_power is 0, the first check will always pass, |
406 | * but not the second one. |
433 | * but not the second one. |
407 | */ |
434 | */ |
408 | if (ip > 2 *op->item_power && ip > (op->item_power + 3)) { |
435 | if (ip > 2 *op->item_power && ip > (op->item_power + 3)) { |
409 | LOG(llevDebug,"Object %s seems to have too low item power? %d > %d\n", |
436 | LOG(llevDebug,"Object %s seems to have too low item power? %d > %d\n", |
410 | op->name?op->name:"NULL", ip, op->item_power); |
437 | op_debug_info (op), ip, op->item_power); |
411 | } |
438 | } |
412 | |
439 | |
413 | } |
440 | } |
414 | /* Old spellcasting object - need to load in the appropiate object */ |
441 | /* Old spellcasting object - need to load in the appropiate object */ |
415 | if ((op->type == ROD || op->type == WAND || op->type == SCROLL || op->type == HORN |
442 | if ((op->type == ROD || op->type == WAND || op->type == SCROLL || op->type == HORN |
… | |
… | |
438 | } |
465 | } |
439 | |
466 | |
440 | if (QUERY_FLAG(op, FLAG_MONSTER)) { |
467 | if (QUERY_FLAG(op, FLAG_MONSTER)) { |
441 | if (op->stats.hp > op->stats.maxhp) |
468 | if (op->stats.hp > op->stats.maxhp) |
442 | LOG(llevDebug,"Monster %s has hp set higher than maxhp (%d>%d)\n", |
469 | LOG(llevDebug,"Monster %s has hp set higher than maxhp (%d>%d)\n", |
443 | op->name, |
470 | op_debug_info (op), |
444 | op->stats.hp, op->stats.maxhp); |
471 | op->stats.hp, op->stats.maxhp); |
445 | |
472 | |
446 | /* The archs just need to be updated for this */ |
473 | /* The archs just need to be updated for this */ |
447 | if (op->move_type ==0) op->move_type = MOVE_WALK; |
474 | if (op->move_type ==0) op->move_type = MOVE_WALK; |
448 | } |
475 | } |
… | |
… | |
616 | |
643 | |
617 | %} |
644 | %} |
618 | |
645 | |
619 | ^msg{WS}$ { BEGIN( MESSAGE ); msgbuf[0]='\0'; } |
646 | ^msg{WS}$ { BEGIN( MESSAGE ); msgbuf[0]='\0'; } |
620 | <MESSAGE>^endmsg{WS}$ { BEGIN( INITIAL ); |
647 | <MESSAGE>^endmsg{WS}$ { BEGIN( INITIAL ); |
621 | op->msg=add_string(msgbuf); |
|
|
622 | /* Just print a warning so we can be reasonably safe |
648 | /* Just print a warning so we can be reasonably safe |
623 | * about not overflowing the buffer. |
649 | * about not overflowing the buffer. |
624 | */ |
650 | */ |
625 | if (strlen(op->msg) > (HUGE_BUF/2)) |
651 | if (strlen(msgbuf) >= HUGE_BUF) |
|
|
652 | { |
626 | LOG(llevDebug, "\n\tWarning message length > %d (max allowed=%d): %d\n>%.80s<\n", |
653 | LOG(llevDebug, "\n\tError message length >= %d: %d\n>%.80s<\n", |
627 | HUGE_BUF/2, HUGE_BUF, strlen(op->msg),op->msg); |
654 | HUGE_BUF, strlen(op->msg),op->msg); |
|
|
655 | op->msg = add_string ("ERROR, please report: string too long, winged.\n"); |
|
|
656 | } |
|
|
657 | else |
|
|
658 | op->msg = add_string (msgbuf); |
628 | } |
659 | } |
629 | <MESSAGE>.* {strcat(msgbuf, yytext); strcat(msgbuf,"\n"); } |
660 | <MESSAGE>.* {strcat(msgbuf, yytext); strcat(msgbuf,"\n"); } |
630 | |
661 | |
631 | ^lore{WS}$ { BEGIN( LORE ); lorebuf[0]='\0'; } |
662 | ^lore{WS}$ { BEGIN( LORE ); lorebuf[0]='\0'; } |
632 | <LORE>^endlore{WS}$ { BEGIN( INITIAL ); |
663 | <LORE>^endlore{WS}$ { BEGIN( INITIAL ); |
… | |
… | |
662 | ^name_pl{S} { char *yv=yval(); |
693 | ^name_pl{S} { char *yv=yval(); |
663 | |
694 | |
664 | if (*yv=='\0') LOG(llevError,"Name without val\n"); |
695 | if (*yv=='\0') LOG(llevError,"Name without val\n"); |
665 | else FREE_AND_COPY(op->name_pl, yv); |
696 | else FREE_AND_COPY(op->name_pl, yv); |
666 | } |
697 | } |
|
|
698 | ^attach{S} { char *yv=yval(); |
|
|
699 | if (*yv) |
|
|
700 | op->attach = add_string (yv); |
|
|
701 | } |
667 | ^skill{S} FREE_AND_COPY(op->skill,yval()); |
702 | ^skill{S} FREE_AND_COPY(op->skill,yval()); |
668 | ^custom_name{S} { char *yv=yval(); |
703 | ^custom_name{S} { char *yv=yval(); |
669 | |
704 | |
670 | if (*yv=='\0') LOG(llevError,"Custom name without val\n"); |
705 | if (*yv=='\0') LOG(llevError,"Custom name without val\n"); |
671 | else FREE_AND_COPY(op->custom_name, yv); |
706 | else FREE_AND_COPY(op->custom_name, yv); |
… | |
… | |
681 | */ |
716 | */ |
682 | if (op->arch) { |
717 | if (op->arch) { |
683 | object *tmp; |
718 | object *tmp; |
684 | char *yv=yval(); |
719 | char *yv=yval(); |
685 | |
720 | |
686 | tmp=get_object(); |
|
|
687 | tmp->arch = find_archetype(yv); |
721 | archetype *arch = find_archetype(yv); |
688 | if (tmp->arch!=NULL) |
722 | if (arch!=NULL) |
689 | copy_object(&tmp->arch->clone,tmp); |
723 | tmp = arch_to_object (arch); |
690 | else { |
724 | else { |
|
|
725 | tmp = get_object (); |
691 | if (tmp->name) free_string(tmp->name); |
726 | if (tmp->name) free_string(tmp->name); |
692 | /* record the name of the broken object */ |
727 | /* record the name of the broken object */ |
693 | tmp->name = add_string(yv); |
728 | tmp->name = add_string(yv); |
694 | } |
729 | } |
695 | strcpy(msgbuf, ""); |
730 | strcpy(msgbuf, ""); |
696 | strcpy(lorebuf, ""); |
731 | strcpy(lorebuf, ""); |
697 | lex_load(tmp, map_flags); |
732 | lex_load(tmp, thawer, map_flags); |
698 | if (tmp->arch) { |
733 | if (tmp->arch) { |
699 | insert_ob_in_ob(tmp,op); |
734 | insert_ob_in_ob(tmp,op); |
700 | } |
735 | } |
701 | else { |
736 | else { |
702 | LOG(llevDebug,"Discarding object without arch: %s\n", tmp->name?tmp->name:"(null)"); |
737 | LOG(llevDebug,"Discarding object without arch: %s\n", tmp->name?tmp->name:"(null)"); |
… | |
… | |
706 | /* This is the actual archetype definition then */ |
741 | /* This is the actual archetype definition then */ |
707 | else { |
742 | else { |
708 | char *yv=yval(); |
743 | char *yv=yval(); |
709 | |
744 | |
710 | op->arch=find_archetype(yv); |
745 | op->arch=find_archetype(yv); |
711 | if (op->arch!=NULL) copy_object(&op->arch->clone,op); |
746 | if (op->arch!=NULL) { |
712 | else if (!arch_init) { |
747 | copy_object(&op->arch->clone,op); |
|
|
748 | } else if (!arch_init) { |
713 | if (op->name) free_string(op->name); |
749 | if (op->name) free_string(op->name); |
714 | /* record the name of the broken object */ |
750 | /* record the name of the broken object */ |
715 | op->name = add_string(yv); |
751 | op->name = add_string(yv); |
716 | } |
752 | } |
717 | } |
753 | } |
… | |
… | |
731 | ^more{WS}$ { /* We need to record that this is a multipart object, |
767 | ^more{WS}$ { /* We need to record that this is a multipart object, |
732 | * so the calling function can glue things back together |
768 | * so the calling function can glue things back together |
733 | */ |
769 | */ |
734 | ismore=1; |
770 | ismore=1; |
735 | } |
771 | } |
736 | |
|
|
737 | ^end{WS}$ { check_loaded_object(op); |
772 | ^end{WS}$ { check_loaded_object(op); |
|
|
773 | |
|
|
774 | if (!arch_init) |
|
|
775 | op->instantiate (); |
|
|
776 | |
738 | if (ismore) return LL_MORE; |
777 | if (ismore) return LL_MORE; |
739 | else return LL_NORMAL; |
778 | else return LL_NORMAL; |
740 | } |
779 | } |
|
|
780 | ^oid{S} { |
|
|
781 | thawer.get (op, IVAL); |
|
|
782 | } |
741 | ^last_heal{S} op->last_heal = IVAL; |
783 | ^last_heal{S} op->last_heal = IVAL; |
742 | ^last_sp{S} op->last_sp = IVAL; |
784 | ^last_sp{S} op->last_sp = IVAL; |
743 | ^last_grace{S} op->last_grace = IVAL; |
785 | ^last_grace{S} op->last_grace = IVAL; |
744 | ^last_eat{S} op->last_eat = IVAL; |
786 | ^last_eat{S} op->last_eat = IVAL; |
745 | ^speed{S} { op->speed = FVAL; |
787 | ^speed{S} { op->speed = FVAL; |
… | |
… | |
834 | ^neutral{S} SET_OR_CLEAR_FLAG(op, FLAG_NEUTRAL, IVAL); |
876 | ^neutral{S} SET_OR_CLEAR_FLAG(op, FLAG_NEUTRAL, IVAL); |
835 | ^no_attack{S} SET_OR_CLEAR_FLAG(op, FLAG_NO_ATTACK, IVAL); |
877 | ^no_attack{S} SET_OR_CLEAR_FLAG(op, FLAG_NO_ATTACK, IVAL); |
836 | ^no_damage{S} SET_OR_CLEAR_FLAG(op, FLAG_NO_DAMAGE, IVAL); |
878 | ^no_damage{S} SET_OR_CLEAR_FLAG(op, FLAG_NO_DAMAGE, IVAL); |
837 | ^friendly{S} { if (IVAL) { |
879 | ^friendly{S} { if (IVAL) { |
838 | SET_FLAG(op, FLAG_FRIENDLY); |
880 | SET_FLAG(op, FLAG_FRIENDLY); |
839 | if (op->type != PLAYER) { |
881 | if (op->type != PLAYER) |
840 | LOG(llevDebug," Adding friendly object %s.\n",op->name); |
|
|
841 | add_friendly_object(op); |
882 | add_friendly_object (op); |
842 | } |
|
|
843 | } |
883 | } |
844 | else CLEAR_FLAG(op, FLAG_FRIENDLY); |
884 | else CLEAR_FLAG(op, FLAG_FRIENDLY); |
845 | } |
885 | } |
846 | ^generator{S} SET_OR_CLEAR_FLAG(op, FLAG_GENERATOR, IVAL); |
886 | ^generator{S} SET_OR_CLEAR_FLAG(op, FLAG_GENERATOR, IVAL); |
847 | ^use_content_on_gen{S} SET_OR_CLEAR_FLAG (op,FLAG_CONTENT_ON_GEN, IVAL); |
887 | ^use_content_on_gen{S} SET_OR_CLEAR_FLAG (op,FLAG_CONTENT_ON_GEN, IVAL); |
… | |
… | |
955 | ^resist_disease{S} SET_RESIST(op, ATNR_DISEASE, IVAL); |
995 | ^resist_disease{S} SET_RESIST(op, ATNR_DISEASE, IVAL); |
956 | |
996 | |
957 | /* Old style resistances */ |
997 | /* Old style resistances */ |
958 | ^immune{S} set_protection(op, IVAL, RESIST_IMMUNE); |
998 | ^immune{S} set_protection(op, IVAL, RESIST_IMMUNE); |
959 | ^protected{S} set_protection(op, IVAL, RESIST_PROT); |
999 | ^protected{S} set_protection(op, IVAL, RESIST_PROT); |
960 | ^vulnerable{S} set_protection(op, IVAL, RESIST_VULN); |
1000 | ^vulnerable{S} set_protection(op, IVAL, (uint16) RESIST_VULN); |
961 | |
1001 | |
962 | /* old values - keep them around for now, but they should be removed at some point */ |
1002 | /* old values - keep them around for now, but they should be removed at some point */ |
963 | ^has_ready_rod{S} SET_OR_CLEAR_FLAG(op, FLAG_READY_RANGE, IVAL); |
1003 | ^has_ready_rod{S} SET_OR_CLEAR_FLAG(op, FLAG_READY_RANGE, IVAL); |
964 | ^has_ready_horn{S} SET_OR_CLEAR_FLAG(op, FLAG_READY_RANGE, IVAL); |
1004 | ^has_ready_horn{S} SET_OR_CLEAR_FLAG(op, FLAG_READY_RANGE, IVAL); |
965 | ^has_ready_wand{S} SET_OR_CLEAR_FLAG(op, FLAG_READY_RANGE, IVAL); |
1005 | ^has_ready_wand{S} SET_OR_CLEAR_FLAG(op, FLAG_READY_RANGE, IVAL); |
… | |
… | |
1004 | ^can_impale{S} { /* That these are for the new combat code */ } |
1044 | ^can_impale{S} { /* That these are for the new combat code */ } |
1005 | ^can_cut{S} { /* just ignore for now */ } |
1045 | ^can_cut{S} { /* just ignore for now */ } |
1006 | ^can_dam_armour{S} { } |
1046 | ^can_dam_armour{S} { } |
1007 | ^weapontype{S} op->weapontype = IVAL; |
1047 | ^weapontype{S} op->weapontype = IVAL; |
1008 | ^tooltype{S} op->tooltype = IVAL; |
1048 | ^tooltype{S} op->tooltype = IVAL; |
1009 | ^casting_time{S} op->casting_time = FVAL; |
1049 | ^casting_time{S} op->casting_time = (sint16) FVAL; |
1010 | ^elevation{S} op->elevation = IVAL; |
1050 | ^elevation{S} op->elevation = IVAL; |
1011 | ^smoothlevel{S} op->smoothlevel = IVAL; |
1051 | ^smoothlevel{S} op->smoothlevel = IVAL; |
1012 | ^client_type{S} op->client_type = IVAL; |
1052 | ^client_type{S} op->client_type = IVAL; |
1013 | ^body_{A} set_body_info(op, yytext); |
1053 | ^body_{A} set_body_info(op, yytext); |
1014 | ^duration{S} op->duration = IVAL; |
1054 | ^duration{S} op->duration = IVAL; |
… | |
… | |
1369 | * be reset. |
1409 | * be reset. |
1370 | * LO_NOREAD (3): Reset the buffers, but don't read from it. (op can be null) |
1410 | * LO_NOREAD (3): Reset the buffers, but don't read from it. (op can be null) |
1371 | * |
1411 | * |
1372 | */ |
1412 | */ |
1373 | |
1413 | |
1374 | int load_object(FILE *fp, object *op, int bufstate, int map_flags) { |
1414 | int load_object(object_thawer &fp, object *op, int bufstate, int map_flags) { |
1375 | int retval; |
1415 | int retval; |
1376 | char inbuf[MAX_BUF]; |
1416 | char inbuf[MAX_BUF]; |
1377 | |
1417 | |
1378 | strcpy(msgbuf, ""); |
1418 | strcpy(msgbuf, ""); |
1379 | strcpy(lorebuf, ""); |
1419 | strcpy(lorebuf, ""); |
… | |
… | |
1385 | } |
1425 | } |
1386 | if (bufstate==LO_LINEMODE) { |
1426 | if (bufstate==LO_LINEMODE) { |
1387 | YY_BUFFER_STATE yybufstate; |
1427 | YY_BUFFER_STATE yybufstate; |
1388 | while (fgets(inbuf, MAX_BUF-3, fp)) { |
1428 | while (fgets(inbuf, MAX_BUF-3, fp)) { |
1389 | yybufstate=yy_scan_string(inbuf); |
1429 | yybufstate=yy_scan_string(inbuf); |
1390 | retval=lex_load(op, map_flags); |
1430 | retval=lex_load(op, fp, map_flags); |
1391 | yy_delete_buffer(yybufstate); |
1431 | yy_delete_buffer(yybufstate); |
1392 | if (retval==LL_NORMAL) return retval; |
1432 | if (retval==LL_NORMAL) return retval; |
1393 | } |
1433 | } |
1394 | LOG(llevDebug,"Got eof while scanning strings\n"); |
1434 | LOG(llevDebug,"Got eof while scanning strings\n"); |
1395 | return LL_EOF; |
1435 | return LL_EOF; |
1396 | } |
1436 | } |
1397 | |
1437 | |
1398 | retval=lex_load(op, map_flags); |
1438 | retval=lex_load(op, fp, map_flags); |
1399 | if (op->current_weapon_script != NULL) |
1439 | if (op->current_weapon_script != NULL) |
1400 | { |
1440 | { |
1401 | op->current_weapon = find_best_weapon_used_match(op, op->current_weapon_script); |
1441 | op->current_weapon = find_best_weapon_used_match(op, op->current_weapon_script); |
1402 | LOG(llevDebug, "CurrentWeapon Loaded !\n"); |
1442 | LOG(llevDebug, "CurrentWeapon Loaded !\n"); |
1403 | }; |
1443 | }; |
… | |
… | |
1414 | * override values and in c_wiz to mutate values. |
1454 | * override values and in c_wiz to mutate values. |
1415 | */ |
1455 | */ |
1416 | int set_variable(object *op,char *buf) { |
1456 | int set_variable(object *op,char *buf) { |
1417 | YY_BUFFER_STATE yybufstate,yycurbuf=YY_CURRENT_BUFFER; |
1457 | YY_BUFFER_STATE yybufstate,yycurbuf=YY_CURRENT_BUFFER; |
1418 | int retval; |
1458 | int retval; |
|
|
1459 | object_thawer thawer (0); |
1419 | |
1460 | |
1420 | strcpy(msgbuf, ""); |
1461 | strcpy(msgbuf, ""); |
1421 | strcpy(lorebuf, ""); |
1462 | strcpy(lorebuf, ""); |
1422 | yy_push_state(INITIAL); |
1463 | yy_push_state(INITIAL); |
1423 | yybufstate=yy_scan_string(buf); |
1464 | yybufstate=yy_scan_string(buf); |
1424 | retval=lex_load(op,0); |
1465 | retval=lex_load(op,thawer,0); |
1425 | yy_switch_to_buffer(yycurbuf); |
1466 | yy_switch_to_buffer(yycurbuf); |
1426 | yy_delete_buffer(yybufstate); |
1467 | yy_delete_buffer(yybufstate); |
1427 | yy_pop_state(); |
1468 | yy_pop_state(); |
1428 | return retval; |
1469 | return retval; |
1429 | } |
1470 | } |
… | |
… | |
1545 | |
1586 | |
1546 | strcpy(retbuf,""); |
1587 | strcpy(retbuf,""); |
1547 | strcpy(retbuf_all," all"); |
1588 | strcpy(retbuf_all," all"); |
1548 | |
1589 | |
1549 | /* Quick check, and probably fairly common */ |
1590 | /* Quick check, and probably fairly common */ |
1550 | if (mt == MOVE_ALL) return retbuf_all; |
1591 | if (mt == MOVE_ALL) return retbuf_all+1; |
1551 | if (mt == 0) { |
1592 | if (mt == 0) { |
1552 | strcpy(retbuf,"0"); |
1593 | strcpy(retbuf,"0"); |
1553 | return retbuf; |
1594 | return retbuf; |
1554 | } |
1595 | } |
1555 | |
1596 | |
… | |
… | |
1570 | /* Basically, if there is a single negation, return it, eg |
1611 | /* Basically, if there is a single negation, return it, eg |
1571 | * 'all -swim'. But more than that, just return the |
1612 | * 'all -swim'. But more than that, just return the |
1572 | * enumerated values. It doesn't make sense to return |
1613 | * enumerated values. It doesn't make sense to return |
1573 | * 'all -walk -fly_low' - it is shorter to return 'fly_high swim' |
1614 | * 'all -walk -fly_low' - it is shorter to return 'fly_high swim' |
1574 | */ |
1615 | */ |
1575 | if (all_count <=1) return retbuf_all; |
1616 | if (all_count <=1) return retbuf_all+1; |
1576 | else return retbuf; |
1617 | else return retbuf+1; |
1577 | } |
1618 | } |
1578 | |
1619 | |
1579 | |
1620 | |
1580 | /* |
1621 | /* |
1581 | * Returns a pointer to a static string which contains all variables |
1622 | * Returns a pointer to a static string which contains all variables |
… | |
… | |
1618 | * NEVER touch buf between PREPARE_FASTCAT(buf) and |
1659 | * NEVER touch buf between PREPARE_FASTCAT(buf) and |
1619 | * FINISH_FASTCAT(buf) |
1660 | * FINISH_FASTCAT(buf) |
1620 | */ |
1661 | */ |
1621 | static int already_run = 0; |
1662 | static int already_run = 0; |
1622 | static int flag_lens[NUM_FLAGS]; |
1663 | static int flag_lens[NUM_FLAGS]; |
1623 | static char buf2[HUGE_BUF]; |
1664 | char buf2[4096]; // / was HUFE_BUF, which was hugely incorrect, as is this value, but much less so |
1624 | static char buf[HUGE_BUF]; |
1665 | static char buf[128*1024]; // < the assumption is that every object always fits. fixing this bug, however |
1625 | char* fastbuf; |
1666 | char* fastbuf; // \ requires a large rewrite of the code, so its left to the next total rewrite. |
1626 | int tmp; |
1667 | int tmp; |
1627 | int i; |
1668 | int i; |
1628 | #if 0 |
|
|
1629 | /*Memory polluting code. Should help detect problems, very slow*/ |
|
|
1630 | for (i=0;i<HUGE_BUF;i++){ |
|
|
1631 | buf[i]='a'+(unsigned short)(i%25); |
|
|
1632 | } |
|
|
1633 | #endif |
|
|
1634 | event *etmp; |
1669 | event *etmp; |
1635 | event *etmp2; |
1670 | event *etmp2; |
1636 | key_value * my_field; |
1671 | key_value * my_field; |
1637 | key_value * arch_field; |
1672 | key_value * arch_field; |
1638 | |
1673 | |
… | |
… | |
1767 | if(op->stats.maxgrace!=op2->stats.maxgrace) |
1802 | if(op->stats.maxgrace!=op2->stats.maxgrace) |
1768 | FAST_SAVE_LONG(fastbuf,"maxgrace ",op->stats.maxgrace,9); |
1803 | FAST_SAVE_LONG(fastbuf,"maxgrace ",op->stats.maxgrace,9); |
1769 | |
1804 | |
1770 | if(op->stats.exp!=op2->stats.exp) { |
1805 | if(op->stats.exp!=op2->stats.exp) { |
1771 | #ifndef WIN32 |
1806 | #ifndef WIN32 |
1772 | sprintf(buf2,"%lld\n", op->stats.exp); |
1807 | sprintf(buf2,"%lld", op->stats.exp); |
1773 | #else |
1808 | #else |
1774 | sprintf(buf2,"%I64d\n", op->stats.exp); |
1809 | sprintf(buf2,"%I64d", op->stats.exp); |
1775 | #endif |
1810 | #endif |
1776 | ADD_STRINGLINE_ENTRY(fastbuf,"exp ", buf2, 4); |
1811 | ADD_STRINGLINE_ENTRY(fastbuf,"exp ", buf2, 4); |
1777 | } |
1812 | } |
1778 | |
1813 | |
1779 | if(op->perm_exp!=op2->perm_exp) { |
1814 | if(op->perm_exp!=op2->perm_exp) { |
1780 | #ifndef WIN32 |
1815 | #ifndef WIN32 |
1781 | sprintf(buf2,"%lld\n", op->perm_exp); |
1816 | sprintf(buf2,"%lld", op->perm_exp); |
1782 | #else |
1817 | #else |
1783 | sprintf(buf2,"%I64d\n", op->perm_exp); |
1818 | sprintf(buf2,"%I64d", op->perm_exp); |
1784 | #endif |
1819 | #endif |
1785 | ADD_STRINGLINE_ENTRY(fastbuf,"perm_exp ", buf2, 9); |
1820 | ADD_STRINGLINE_ENTRY(fastbuf,"perm_exp ", buf2, 9); |
1786 | } |
1821 | } |
1787 | |
1822 | |
1788 | if(op->expmul!=op2->expmul) |
1823 | if(op->expmul!=op2->expmul) |
… | |
… | |
1933 | * save (say to a temp map, where we don't care about strings), |
1968 | * save (say to a temp map, where we don't care about strings), |
1934 | * or a slower save/dm dump, where printing out strings is handy. |
1969 | * or a slower save/dm dump, where printing out strings is handy. |
1935 | */ |
1970 | */ |
1936 | if (op->move_type != op2->move_type) { |
1971 | if (op->move_type != op2->move_type) { |
1937 | /*FAST_SAVE_LONG(fastbuf,"move_type ",op->move_type,10)*/ |
1972 | /*FAST_SAVE_LONG(fastbuf,"move_type ",op->move_type,10)*/ |
1938 | ADD_STRINGLINE_ENTRY(fastbuf,"move_type ", |
1973 | ADD_STRINGLINE_ENTRY(fastbuf,"move_type ", |
1939 | get_string_move_type(op->move_type), |
1974 | get_string_move_type(op->move_type), |
1940 | 10); |
1975 | 10); |
1941 | } |
1976 | } |
1942 | if (op->move_block != op2->move_block) { |
1977 | if (op->move_block != op2->move_block) { |
1943 | /*FAST_SAVE_LONG(fastbuf,"move_block ",op->move_block,11)*/ |
1978 | /*FAST_SAVE_LONG(fastbuf,"move_block ",op->move_block,11)*/ |
1944 | ADD_STRINGLINE_ENTRY(fastbuf,"move_block ", |
1979 | ADD_STRINGLINE_ENTRY(fastbuf,"move_block ", |
1945 | get_string_move_type(op->move_block), |
1980 | get_string_move_type(op->move_block), |
1946 | 11); |
1981 | 11); |
1947 | } |
1982 | } |
1948 | if (op->move_allow != op2->move_allow) { |
1983 | if (op->move_allow != op2->move_allow) { |
1949 | /*FAST_SAVE_LONG(fastbuf,"move_allow ",op->move_allow,11);*/ |
1984 | /*FAST_SAVE_LONG(fastbuf,"move_allow ",op->move_allow,11);*/ |
1950 | ADD_STRINGLINE_ENTRY(fastbuf,"move_allow ", |
1985 | ADD_STRINGLINE_ENTRY(fastbuf,"move_allow ", |
1951 | get_string_move_type(op->move_allow), |
1986 | get_string_move_type(op->move_allow), |
1952 | 11); |
1987 | 11); |
1953 | } |
1988 | } |
1954 | if (op->move_on != op2->move_on) { |
1989 | if (op->move_on != op2->move_on) { |
1955 | /*FAST_SAVE_LONG(fastbuf,"move_on ",op->move_on,8);*/ |
1990 | /*FAST_SAVE_LONG(fastbuf,"move_on ",op->move_on,8);*/ |
1956 | ADD_STRINGLINE_ENTRY(fastbuf,"move_on ", |
1991 | ADD_STRINGLINE_ENTRY(fastbuf,"move_on ", |
1957 | get_string_move_type(op->move_on), |
1992 | get_string_move_type(op->move_on), |
1958 | 8); |
1993 | 8); |
1959 | } |
1994 | } |
1960 | if (op->move_off != op2->move_off) { |
1995 | if (op->move_off != op2->move_off) { |
1961 | /*FAST_SAVE_LONG(fastbuf,"move_off ",op->move_off,9);*/ |
1996 | /*FAST_SAVE_LONG(fastbuf,"move_off ",op->move_off,9);*/ |
1962 | ADD_STRINGLINE_ENTRY(fastbuf,"move_off ", |
1997 | ADD_STRINGLINE_ENTRY(fastbuf,"move_off ", |
1963 | get_string_move_type(op->move_off), |
1998 | get_string_move_type(op->move_off), |
1964 | 9); |
1999 | 9); |
1965 | } |
2000 | } |
1966 | if (op->move_slow != op2->move_slow) { |
2001 | if (op->move_slow != op2->move_slow) { |
1967 | /*FAST_SAVE_LONG(fastbuf,"move_slow ",op->move_slow,10);*/ |
2002 | /*FAST_SAVE_LONG(fastbuf,"move_slow ",op->move_slow,10);*/ |
1968 | ADD_STRINGLINE_ENTRY(fastbuf,"move_slow ", |
2003 | ADD_STRINGLINE_ENTRY(fastbuf,"move_slow ", |
1969 | get_string_move_type(op->move_slow), |
2004 | get_string_move_type(op->move_slow), |
1970 | 10); |
2005 | 10); |
1971 | } |
2006 | } |
1972 | |
2007 | |
1973 | if (op->move_slow_penalty != op2->move_slow_penalty) { |
2008 | if (op->move_slow_penalty != op2->move_slow_penalty) { |
1974 | FAST_SAVE_LONG(fastbuf,"move_slow_penalty ",op->move_slow_penalty,18); |
2009 | FAST_SAVE_LONG(fastbuf,"move_slow_penalty ",(long) op->move_slow_penalty,18); |
1975 | } |
2010 | } |
1976 | |
2011 | |
1977 | if (!COMPARE_FLAGS(op,op2)) { |
2012 | if (!COMPARE_FLAGS(op,op2)) { |
1978 | for (tmp=0; tmp <= NUM_FLAGS; tmp++) { |
2013 | for (tmp=0; tmp <= NUM_FLAGS; tmp++) { |
1979 | if (flag_names[tmp] && (QUERY_FLAG(op, tmp) != QUERY_FLAG(op2, tmp))) { |
2014 | if (flag_names[tmp] && (QUERY_FLAG(op, tmp) != QUERY_FLAG(op2, tmp))) { |
… | |
… | |
2002 | * the only place this is not set is when saving the player. |
2037 | * the only place this is not set is when saving the player. |
2003 | * If bit 1 of flag is set, don't remove the object after save. As of now, |
2038 | * If bit 1 of flag is set, don't remove the object after save. As of now, |
2004 | * all of the callers are setting this. |
2039 | * all of the callers are setting this. |
2005 | */ |
2040 | */ |
2006 | |
2041 | |
2007 | void save_object(FILE *fp,object *op, int flag) { |
2042 | void save_object(object_freezer &fp,object *op, int flag) { |
2008 | archetype *at; |
2043 | archetype *at; |
2009 | char *cp; |
2044 | char *cp; |
2010 | object *tmp,*old; |
2045 | object *tmp,*old; |
2011 | |
2046 | |
2012 | /* Even if the object does have an owner, it would seem that we should |
2047 | /* Even if the object does have an owner, it would seem that we should |
… | |
… | |
2051 | if (!(flag&2)) { |
2086 | if (!(flag&2)) { |
2052 | remove_ob(op); |
2087 | remove_ob(op); |
2053 | free_object (op); |
2088 | free_object (op); |
2054 | } |
2089 | } |
2055 | |
2090 | |
|
|
2091 | fp.put (op); |
2056 | fprintf(fp,"end\n"); |
2092 | fprintf(fp,"end\n"); |
2057 | } |
2093 | } |
2058 | |
2094 | |
2059 | void insert_event(object* op, int etype, char *ehook, char *eplug, char *eoptions) |
2095 | void insert_event(object* op, int etype, char *ehook, char *eplug, char *eoptions) |
2060 | { |
2096 | { |