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.8 by root, Sat Aug 26 08:44:04 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.8 2006/08/26 08:44:04 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[65536]; 45static char msgbuf[65536];
716 */ 716 */
717 if (op->arch) { 717 if (op->arch) {
718 object *tmp; 718 object *tmp;
719 char *yv=yval(); 719 char *yv=yval();
720 720
721 tmp=get_object();
722 tmp->arch = find_archetype(yv); 721 archetype *arch = find_archetype(yv);
723 if (tmp->arch!=NULL) 722 if (arch!=NULL)
724 copy_object(&tmp->arch->clone,tmp); 723 tmp = arch_to_object (arch);
725 else { 724 else {
725 tmp = get_object ();
726 if (tmp->name) free_string(tmp->name); 726 if (tmp->name) free_string(tmp->name);
727 /* record the name of the broken object */ 727 /* record the name of the broken object */
728 tmp->name = add_string(yv); 728 tmp->name = add_string(yv);
729 } 729 }
730 strcpy(msgbuf, ""); 730 strcpy(msgbuf, "");
731 strcpy(lorebuf, ""); 731 strcpy(lorebuf, "");
732 lex_load(tmp, map_flags); 732 lex_load(tmp, thawer, map_flags);
733 if (tmp->arch) { 733 if (tmp->arch) {
734 insert_ob_in_ob(tmp,op); 734 insert_ob_in_ob(tmp,op);
735 } 735 }
736 else { 736 else {
737 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)");
741 /* This is the actual archetype definition then */ 741 /* This is the actual archetype definition then */
742 else { 742 else {
743 char *yv=yval(); 743 char *yv=yval();
744 744
745 op->arch=find_archetype(yv); 745 op->arch=find_archetype(yv);
746 if (op->arch!=NULL) copy_object(&op->arch->clone,op); 746 if (op->arch!=NULL) {
747 else if (!arch_init) { 747 copy_object(&op->arch->clone,op);
748 } else if (!arch_init) {
748 if (op->name) free_string(op->name); 749 if (op->name) free_string(op->name);
749 /* record the name of the broken object */ 750 /* record the name of the broken object */
750 op->name = add_string(yv); 751 op->name = add_string(yv);
751 } 752 }
752 } 753 }
766^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,
767 * so the calling function can glue things back together 768 * so the calling function can glue things back together
768 */ 769 */
769 ismore=1; 770 ismore=1;
770 } 771 }
771
772^end{WS}$ { check_loaded_object(op); 772^end{WS}$ { check_loaded_object(op);
773
774 if (!arch_init)
775 op->instantiate ();
776
773 if (ismore) return LL_MORE; 777 if (ismore) return LL_MORE;
774 else return LL_NORMAL; 778 else return LL_NORMAL;
775 } 779 }
780^oid{S} {
781 thawer.get (op, IVAL);
782 }
776^last_heal{S} op->last_heal = IVAL; 783^last_heal{S} op->last_heal = IVAL;
777^last_sp{S} op->last_sp = IVAL; 784^last_sp{S} op->last_sp = IVAL;
778^last_grace{S} op->last_grace = IVAL; 785^last_grace{S} op->last_grace = IVAL;
779^last_eat{S} op->last_eat = IVAL; 786^last_eat{S} op->last_eat = IVAL;
780^speed{S} { op->speed = FVAL; 787^speed{S} { op->speed = FVAL;
1402 * be reset. 1409 * be reset.
1403 * 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)
1404 * 1411 *
1405 */ 1412 */
1406 1413
1407int 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) {
1408 int retval; 1415 int retval;
1409 char inbuf[MAX_BUF]; 1416 char inbuf[MAX_BUF];
1410 1417
1411 strcpy(msgbuf, ""); 1418 strcpy(msgbuf, "");
1412 strcpy(lorebuf, ""); 1419 strcpy(lorebuf, "");
1418 } 1425 }
1419 if (bufstate==LO_LINEMODE) { 1426 if (bufstate==LO_LINEMODE) {
1420 YY_BUFFER_STATE yybufstate; 1427 YY_BUFFER_STATE yybufstate;
1421 while (fgets(inbuf, MAX_BUF-3, fp)) { 1428 while (fgets(inbuf, MAX_BUF-3, fp)) {
1422 yybufstate=yy_scan_string(inbuf); 1429 yybufstate=yy_scan_string(inbuf);
1423 retval=lex_load(op, map_flags); 1430 retval=lex_load(op, thawer, map_flags);
1424 yy_delete_buffer(yybufstate); 1431 yy_delete_buffer(yybufstate);
1425 if (retval==LL_NORMAL) return retval; 1432 if (retval==LL_NORMAL) return retval;
1426 } 1433 }
1427 LOG(llevDebug,"Got eof while scanning strings\n"); 1434 LOG(llevDebug,"Got eof while scanning strings\n");
1428 return LL_EOF; 1435 return LL_EOF;
1429 } 1436 }
1430 1437
1431 retval=lex_load(op, map_flags); 1438 retval=lex_load(op, thawer, map_flags);
1432 if (op->current_weapon_script != NULL) 1439 if (op->current_weapon_script != NULL)
1433 { 1440 {
1434 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);
1435 LOG(llevDebug, "CurrentWeapon Loaded !\n"); 1442 LOG(llevDebug, "CurrentWeapon Loaded !\n");
1436 }; 1443 };
1447 * override values and in c_wiz to mutate values. 1454 * override values and in c_wiz to mutate values.
1448 */ 1455 */
1449int set_variable(object *op,char *buf) { 1456int set_variable(object *op,char *buf) {
1450 YY_BUFFER_STATE yybufstate,yycurbuf=YY_CURRENT_BUFFER; 1457 YY_BUFFER_STATE yybufstate,yycurbuf=YY_CURRENT_BUFFER;
1451 int retval; 1458 int retval;
1459 object_thawer thawer;
1452 1460
1453 strcpy(msgbuf, ""); 1461 strcpy(msgbuf, "");
1454 strcpy(lorebuf, ""); 1462 strcpy(lorebuf, "");
1455 yy_push_state(INITIAL); 1463 yy_push_state(INITIAL);
1456 yybufstate=yy_scan_string(buf); 1464 yybufstate=yy_scan_string(buf);
1457 retval=lex_load(op,0); 1465 retval=lex_load(op,thawer,0);
1458 yy_switch_to_buffer(yycurbuf); 1466 yy_switch_to_buffer(yycurbuf);
1459 yy_delete_buffer(yybufstate); 1467 yy_delete_buffer(yybufstate);
1460 yy_pop_state(); 1468 yy_pop_state();
1461 return retval; 1469 return retval;
1462} 1470}
2029 * 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.
2030 * 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,
2031 * all of the callers are setting this. 2039 * all of the callers are setting this.
2032 */ 2040 */
2033 2041
2034void save_object(FILE *fp,object *op, int flag) { 2042void save_object(FILE *fp,object_freezer &freezer,object *op, int flag) {
2035 archetype *at; 2043 archetype *at;
2036 char *cp; 2044 char *cp;
2037 object *tmp,*old; 2045 object *tmp,*old;
2038 2046
2039 /* 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
2057 2065
2058 old=NULL; 2066 old=NULL;
2059 2067
2060 if (flag & 2 ) 2068 if (flag & 2 )
2061 for(tmp=op->inv;tmp!=NULL;tmp=tmp->below) 2069 for(tmp=op->inv;tmp!=NULL;tmp=tmp->below)
2062 save_object(fp,tmp,flag); 2070 save_object(fp,freezer,tmp,flag);
2063 2071
2064 /* Slightly different logic because tmp/op will be removed by 2072 /* Slightly different logic because tmp/op will be removed by
2065 * 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
2066 * until there is nothing left. In theory, the variable old 2074 * until there is nothing left. In theory, the variable old
2067 * should not be needed, as recursive loops shouldn't happen. 2075 * should not be needed, as recursive loops shouldn't happen.
2069 else while ((tmp=op->inv)!=NULL) { 2077 else while ((tmp=op->inv)!=NULL) {
2070 if(old==tmp) { 2078 if(old==tmp) {
2071 LOG(llevError," Recursive loop in inventory\n"); 2079 LOG(llevError," Recursive loop in inventory\n");
2072 break; 2080 break;
2073 } 2081 }
2074 save_object(fp,tmp,flag); 2082 save_object(fp,freezer,tmp,flag);
2075 old=tmp; 2083 old=tmp;
2076 } 2084 }
2077 2085
2078 if (!(flag&2)) { 2086 if (!(flag&2)) {
2079 remove_ob(op); 2087 remove_ob(op);
2080 free_object (op); 2088 free_object (op);
2081 } 2089 }
2082 2090
2091 freezer.put (fp, op);
2083 fprintf(fp,"end\n"); 2092 fprintf(fp,"end\n");
2084} 2093}
2085 2094
2086void 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)
2087{ 2096{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines