ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/loader.l
(Generate patch)

Comparing deliantra/server/common/loader.l (file contents):
Revision 1.4 by root, Thu May 11 20:15:30 2006 UTC vs.
Revision 1.12 by root, Mon Aug 28 07:07:41 2006 UTC

1%{ 1%{
2/* 2/*
3 * static char *rcsid_object_c = 3 * static char *rcsid_object_c =
4 * "$Id: loader.l,v 1.4 2006/05/11 20:15:30 root Exp $"; 4 * "$Id: loader.l,v 1.12 2006/08/28 07:07:41 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
42static char *yval(); 42static char *yval();
43 43
44static int lex_error; 44static int lex_error;
45static char msgbuf[HUGE_BUF]; 45static char msgbuf[65536];
46static char lorebuf[HUGE_BUF]; 46static char lorebuf[65536];
47 47
48/* Maps the MOVE_* values to names */ 48/* Maps the MOVE_* values to names */
49static const char *const move_name[] = {"walk", "fly_low", "fly_high", "swim", "boat", 49static 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 */
62const char *const spell_mapping[] = { 62const 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 */
643 643
644%} 644%}
645 645
646^msg{WS}$ { BEGIN( MESSAGE ); msgbuf[0]='\0'; } 646^msg{WS}$ { BEGIN( MESSAGE ); msgbuf[0]='\0'; }
647<MESSAGE>^endmsg{WS}$ { BEGIN( INITIAL ); 647<MESSAGE>^endmsg{WS}$ { BEGIN( INITIAL );
648 op->msg=add_string(msgbuf);
649 /* Just print a warning so we can be reasonably safe 648 /* Just print a warning so we can be reasonably safe
650 * about not overflowing the buffer. 649 * about not overflowing the buffer.
651 */ 650 */
652 if (strlen(op->msg) > (HUGE_BUF/2)) 651 if (strlen(msgbuf) >= HUGE_BUF)
652 {
653 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",
654 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);
655 } 659 }
656<MESSAGE>.* {strcat(msgbuf, yytext); strcat(msgbuf,"\n"); } 660<MESSAGE>.* {strcat(msgbuf, yytext); strcat(msgbuf,"\n"); }
657 661
658^lore{WS}$ { BEGIN( LORE ); lorebuf[0]='\0'; } 662^lore{WS}$ { BEGIN( LORE ); lorebuf[0]='\0'; }
659<LORE>^endlore{WS}$ { BEGIN( INITIAL ); 663<LORE>^endlore{WS}$ { BEGIN( INITIAL );
689^name_pl{S} { char *yv=yval(); 693^name_pl{S} { char *yv=yval();
690 694
691 if (*yv=='\0') LOG(llevError,"Name without val\n"); 695 if (*yv=='\0') LOG(llevError,"Name without val\n");
692 else FREE_AND_COPY(op->name_pl, yv); 696 else FREE_AND_COPY(op->name_pl, yv);
693 } 697 }
698^attach{S} { char *yv=yval();
699 if (*yv)
700 op->attach = add_string (yv);
701 }
694^skill{S} FREE_AND_COPY(op->skill,yval()); 702^skill{S} FREE_AND_COPY(op->skill,yval());
695^custom_name{S} { char *yv=yval(); 703^custom_name{S} { char *yv=yval();
696 704
697 if (*yv=='\0') LOG(llevError,"Custom name without val\n"); 705 if (*yv=='\0') LOG(llevError,"Custom name without val\n");
698 else FREE_AND_COPY(op->custom_name, yv); 706 else FREE_AND_COPY(op->custom_name, yv);
708 */ 716 */
709 if (op->arch) { 717 if (op->arch) {
710 object *tmp; 718 object *tmp;
711 char *yv=yval(); 719 char *yv=yval();
712 720
713 tmp=get_object();
714 tmp->arch = find_archetype(yv); 721 archetype *arch = find_archetype(yv);
715 if (tmp->arch!=NULL) 722 if (arch!=NULL)
716 copy_object(&tmp->arch->clone,tmp); 723 tmp = arch_to_object (arch);
717 else { 724 else {
725 tmp = get_object ();
718 if (tmp->name) free_string(tmp->name); 726 if (tmp->name) free_string(tmp->name);
719 /* record the name of the broken object */ 727 /* record the name of the broken object */
720 tmp->name = add_string(yv); 728 tmp->name = add_string(yv);
721 } 729 }
722 strcpy(msgbuf, ""); 730 strcpy(msgbuf, "");
723 strcpy(lorebuf, ""); 731 strcpy(lorebuf, "");
724 lex_load(tmp, map_flags); 732 lex_load(tmp, thawer, map_flags);
725 if (tmp->arch) { 733 if (tmp->arch) {
726 insert_ob_in_ob(tmp,op); 734 insert_ob_in_ob(tmp,op);
727 } 735 }
728 else { 736 else {
729 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)");
733 /* This is the actual archetype definition then */ 741 /* This is the actual archetype definition then */
734 else { 742 else {
735 char *yv=yval(); 743 char *yv=yval();
736 744
737 op->arch=find_archetype(yv); 745 op->arch=find_archetype(yv);
738 if (op->arch!=NULL) copy_object(&op->arch->clone,op); 746 if (op->arch!=NULL) {
739 else if (!arch_init) { 747 copy_object(&op->arch->clone,op);
748 } else if (!arch_init) {
740 if (op->name) free_string(op->name); 749 if (op->name) free_string(op->name);
741 /* record the name of the broken object */ 750 /* record the name of the broken object */
742 op->name = add_string(yv); 751 op->name = add_string(yv);
743 } 752 }
744 } 753 }
758^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,
759 * so the calling function can glue things back together 768 * so the calling function can glue things back together
760 */ 769 */
761 ismore=1; 770 ismore=1;
762 } 771 }
763
764^end{WS}$ { check_loaded_object(op); 772^end{WS}$ { check_loaded_object(op);
773
774 if (!arch_init)
775 op->instantiate ();
776
765 if (ismore) return LL_MORE; 777 if (ismore) return LL_MORE;
766 else return LL_NORMAL; 778 else return LL_NORMAL;
767 } 779 }
780^oid{S} {
781 thawer.get (op, IVAL);
782 }
768^last_heal{S} op->last_heal = IVAL; 783^last_heal{S} op->last_heal = IVAL;
769^last_sp{S} op->last_sp = IVAL; 784^last_sp{S} op->last_sp = IVAL;
770^last_grace{S} op->last_grace = IVAL; 785^last_grace{S} op->last_grace = IVAL;
771^last_eat{S} op->last_eat = IVAL; 786^last_eat{S} op->last_eat = IVAL;
772^speed{S} { op->speed = FVAL; 787^speed{S} { op->speed = FVAL;
980^resist_disease{S} SET_RESIST(op, ATNR_DISEASE, IVAL); 995^resist_disease{S} SET_RESIST(op, ATNR_DISEASE, IVAL);
981 996
982 /* Old style resistances */ 997 /* Old style resistances */
983^immune{S} set_protection(op, IVAL, RESIST_IMMUNE); 998^immune{S} set_protection(op, IVAL, RESIST_IMMUNE);
984^protected{S} set_protection(op, IVAL, RESIST_PROT); 999^protected{S} set_protection(op, IVAL, RESIST_PROT);
985^vulnerable{S} set_protection(op, IVAL, RESIST_VULN); 1000^vulnerable{S} set_protection(op, IVAL, (uint16) RESIST_VULN);
986 1001
987 /* 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 */
988^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);
989^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);
990^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);
1029^can_impale{S} { /* That these are for the new combat code */ } 1044^can_impale{S} { /* That these are for the new combat code */ }
1030^can_cut{S} { /* just ignore for now */ } 1045^can_cut{S} { /* just ignore for now */ }
1031^can_dam_armour{S} { } 1046^can_dam_armour{S} { }
1032^weapontype{S} op->weapontype = IVAL; 1047^weapontype{S} op->weapontype = IVAL;
1033^tooltype{S} op->tooltype = IVAL; 1048^tooltype{S} op->tooltype = IVAL;
1034^casting_time{S} op->casting_time = FVAL; 1049^casting_time{S} op->casting_time = (sint16) FVAL;
1035^elevation{S} op->elevation = IVAL; 1050^elevation{S} op->elevation = IVAL;
1036^smoothlevel{S} op->smoothlevel = IVAL; 1051^smoothlevel{S} op->smoothlevel = IVAL;
1037^client_type{S} op->client_type = IVAL; 1052^client_type{S} op->client_type = IVAL;
1038^body_{A} set_body_info(op, yytext); 1053^body_{A} set_body_info(op, yytext);
1039^duration{S} op->duration = IVAL; 1054^duration{S} op->duration = IVAL;
1394 * be reset. 1409 * be reset.
1395 * 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)
1396 * 1411 *
1397 */ 1412 */
1398 1413
1399int load_object(FILE *fp, object *op, int bufstate, int map_flags) { 1414int load_object(FILE *fp, object_thawer &thawer, object *op, int bufstate, int map_flags) {
1400 int retval; 1415 int retval;
1401 char inbuf[MAX_BUF]; 1416 char inbuf[MAX_BUF];
1402 1417
1403 strcpy(msgbuf, ""); 1418 strcpy(msgbuf, "");
1404 strcpy(lorebuf, ""); 1419 strcpy(lorebuf, "");
1410 } 1425 }
1411 if (bufstate==LO_LINEMODE) { 1426 if (bufstate==LO_LINEMODE) {
1412 YY_BUFFER_STATE yybufstate; 1427 YY_BUFFER_STATE yybufstate;
1413 while (fgets(inbuf, MAX_BUF-3, fp)) { 1428 while (fgets(inbuf, MAX_BUF-3, fp)) {
1414 yybufstate=yy_scan_string(inbuf); 1429 yybufstate=yy_scan_string(inbuf);
1415 retval=lex_load(op, map_flags); 1430 retval=lex_load(op, thawer, map_flags);
1416 yy_delete_buffer(yybufstate); 1431 yy_delete_buffer(yybufstate);
1417 if (retval==LL_NORMAL) return retval; 1432 if (retval==LL_NORMAL) return retval;
1418 } 1433 }
1419 LOG(llevDebug,"Got eof while scanning strings\n"); 1434 LOG(llevDebug,"Got eof while scanning strings\n");
1420 return LL_EOF; 1435 return LL_EOF;
1421 } 1436 }
1422 1437
1423 retval=lex_load(op, map_flags); 1438 retval=lex_load(op, thawer, map_flags);
1424 if (op->current_weapon_script != NULL) 1439 if (op->current_weapon_script != NULL)
1425 { 1440 {
1426 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);
1427 LOG(llevDebug, "CurrentWeapon Loaded !\n"); 1442 LOG(llevDebug, "CurrentWeapon Loaded !\n");
1428 }; 1443 };
1439 * override values and in c_wiz to mutate values. 1454 * override values and in c_wiz to mutate values.
1440 */ 1455 */
1441int set_variable(object *op,char *buf) { 1456int set_variable(object *op,char *buf) {
1442 YY_BUFFER_STATE yybufstate,yycurbuf=YY_CURRENT_BUFFER; 1457 YY_BUFFER_STATE yybufstate,yycurbuf=YY_CURRENT_BUFFER;
1443 int retval; 1458 int retval;
1459 object_thawer thawer;
1444 1460
1445 strcpy(msgbuf, ""); 1461 strcpy(msgbuf, "");
1446 strcpy(lorebuf, ""); 1462 strcpy(lorebuf, "");
1447 yy_push_state(INITIAL); 1463 yy_push_state(INITIAL);
1448 yybufstate=yy_scan_string(buf); 1464 yybufstate=yy_scan_string(buf);
1449 retval=lex_load(op,0); 1465 retval=lex_load(op,thawer,0);
1450 yy_switch_to_buffer(yycurbuf); 1466 yy_switch_to_buffer(yycurbuf);
1451 yy_delete_buffer(yybufstate); 1467 yy_delete_buffer(yybufstate);
1452 yy_pop_state(); 1468 yy_pop_state();
1453 return retval; 1469 return retval;
1454} 1470}
1643 * NEVER touch buf between PREPARE_FASTCAT(buf) and 1659 * NEVER touch buf between PREPARE_FASTCAT(buf) and
1644 * FINISH_FASTCAT(buf) 1660 * FINISH_FASTCAT(buf)
1645 */ 1661 */
1646 static int already_run = 0; 1662 static int already_run = 0;
1647 static int flag_lens[NUM_FLAGS]; 1663 static int flag_lens[NUM_FLAGS];
1648 static char buf2[HUGE_BUF]; 1664 char buf2[4096]; // / was HUFE_BUF, which was hugely incorrect, as is this value, but much less so
1649 static char buf[HUGE_BUF]; 1665 static char buf[128*1024]; // < the assumption is that every object always fits. fixing this bug, however
1650 char* fastbuf; 1666 char* fastbuf; // \ requires a large rewrite of the code, so its left to the next total rewrite.
1651 int tmp; 1667 int tmp;
1652 int i; 1668 int i;
1653#if 0
1654/*Memory polluting code. Should help detect problems, very slow*/
1655 for (i=0;i<HUGE_BUF;i++){
1656 buf[i]='a'+(unsigned short)(i%25);
1657 }
1658#endif
1659 event *etmp; 1669 event *etmp;
1660 event *etmp2; 1670 event *etmp2;
1661 key_value * my_field; 1671 key_value * my_field;
1662 key_value * arch_field; 1672 key_value * arch_field;
1663 1673
1994 get_string_move_type(op->move_slow), 2004 get_string_move_type(op->move_slow),
1995 10); 2005 10);
1996 } 2006 }
1997 2007
1998 if (op->move_slow_penalty != op2->move_slow_penalty) { 2008 if (op->move_slow_penalty != op2->move_slow_penalty) {
1999 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);
2000 } 2010 }
2001 2011
2002 if (!COMPARE_FLAGS(op,op2)) { 2012 if (!COMPARE_FLAGS(op,op2)) {
2003 for (tmp=0; tmp <= NUM_FLAGS; tmp++) { 2013 for (tmp=0; tmp <= NUM_FLAGS; tmp++) {
2004 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))) {
2027 * 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.
2028 * 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,
2029 * all of the callers are setting this. 2039 * all of the callers are setting this.
2030 */ 2040 */
2031 2041
2032void save_object(FILE *fp,object *op, int flag) { 2042void save_object(FILE *fp,object_freezer &freezer,object *op, int flag) {
2033 archetype *at; 2043 archetype *at;
2034 char *cp; 2044 char *cp;
2035 object *tmp,*old; 2045 object *tmp,*old;
2036 2046
2037 /* 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
2055 2065
2056 old=NULL; 2066 old=NULL;
2057 2067
2058 if (flag & 2 ) 2068 if (flag & 2 )
2059 for(tmp=op->inv;tmp!=NULL;tmp=tmp->below) 2069 for(tmp=op->inv;tmp!=NULL;tmp=tmp->below)
2060 save_object(fp,tmp,flag); 2070 save_object(fp,freezer,tmp,flag);
2061 2071
2062 /* Slightly different logic because tmp/op will be removed by 2072 /* Slightly different logic because tmp/op will be removed by
2063 * the save_object we call. So we just keep looking at op->inv 2073 * the save_object we call. So we just keep looking at op->inv
2064 * until there is nothing left. In theory, the variable old 2074 * until there is nothing left. In theory, the variable old
2065 * should not be needed, as recursive loops shouldn't happen. 2075 * should not be needed, as recursive loops shouldn't happen.
2067 else while ((tmp=op->inv)!=NULL) { 2077 else while ((tmp=op->inv)!=NULL) {
2068 if(old==tmp) { 2078 if(old==tmp) {
2069 LOG(llevError," Recursive loop in inventory\n"); 2079 LOG(llevError," Recursive loop in inventory\n");
2070 break; 2080 break;
2071 } 2081 }
2072 save_object(fp,tmp,flag); 2082 save_object(fp,freezer,tmp,flag);
2073 old=tmp; 2083 old=tmp;
2074 } 2084 }
2075 2085
2076 if (!(flag&2)) { 2086 if (!(flag&2)) {
2077 remove_ob(op); 2087 remove_ob(op);
2078 free_object (op); 2088 free_object (op);
2079 } 2089 }
2080 2090
2091 freezer.put (fp, op);
2081 fprintf(fp,"end\n"); 2092 fprintf(fp,"end\n");
2082} 2093}
2083 2094
2084void insert_event(object* op, int etype, char *ehook, char *eplug, char *eoptions) 2095void insert_event(object* op, int etype, char *ehook, char *eplug, char *eoptions)
2085{ 2096{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines