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.9 by root, Sat Aug 26 23:36:29 2006 UTC vs.
Revision 1.11 by root, Sun Aug 27 17:59:25 2006 UTC

1%{ 1%{
2/* 2/*
3 * static char *rcsid_object_c = 3 * static char *rcsid_object_c =
4 * "$Id: loader.l,v 1.9 2006/08/26 23:36:29 root Exp $"; 4 * "$Id: loader.l,v 1.11 2006/08/27 17:59:25 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];
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)");
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) { 746 if (op->arch!=NULL) {
747 copy_object(&op->arch->clone,op); 747 copy_object(&op->arch->clone,op);
748 op->instantiate ();
749 } else if (!arch_init) { 748 } else if (!arch_init) {
750 if (op->name) free_string(op->name); 749 if (op->name) free_string(op->name);
751 /* record the name of the broken object */ 750 /* record the name of the broken object */
752 op->name = add_string(yv); 751 op->name = add_string(yv);
753 } 752 }
770 */ 769 */
771 ismore=1; 770 ismore=1;
772 } 771 }
773 772
774^end{WS}$ { check_loaded_object(op); 773^end{WS}$ { check_loaded_object(op);
774
775 if (!arch_init)
776 {
777 thawer.get (op);
778 op->instantiate ();
779 }
780
775 if (ismore) return LL_MORE; 781 if (ismore) return LL_MORE;
776 else return LL_NORMAL; 782 else return LL_NORMAL;
777 } 783 }
778^last_heal{S} op->last_heal = IVAL; 784^last_heal{S} op->last_heal = IVAL;
779^last_sp{S} op->last_sp = IVAL; 785^last_sp{S} op->last_sp = IVAL;
1404 * be reset. 1410 * be reset.
1405 * LO_NOREAD (3): Reset the buffers, but don't read from it. (op can be null) 1411 * LO_NOREAD (3): Reset the buffers, but don't read from it. (op can be null)
1406 * 1412 *
1407 */ 1413 */
1408 1414
1409int load_object(FILE *fp, object *op, int bufstate, int map_flags) { 1415int load_object(FILE *fp, object_thawer &thawer, object *op, int bufstate, int map_flags) {
1410 int retval; 1416 int retval;
1411 char inbuf[MAX_BUF]; 1417 char inbuf[MAX_BUF];
1412 1418
1413 strcpy(msgbuf, ""); 1419 strcpy(msgbuf, "");
1414 strcpy(lorebuf, ""); 1420 strcpy(lorebuf, "");
1420 } 1426 }
1421 if (bufstate==LO_LINEMODE) { 1427 if (bufstate==LO_LINEMODE) {
1422 YY_BUFFER_STATE yybufstate; 1428 YY_BUFFER_STATE yybufstate;
1423 while (fgets(inbuf, MAX_BUF-3, fp)) { 1429 while (fgets(inbuf, MAX_BUF-3, fp)) {
1424 yybufstate=yy_scan_string(inbuf); 1430 yybufstate=yy_scan_string(inbuf);
1425 retval=lex_load(op, map_flags); 1431 retval=lex_load(op, thawer, map_flags);
1426 yy_delete_buffer(yybufstate); 1432 yy_delete_buffer(yybufstate);
1427 if (retval==LL_NORMAL) return retval; 1433 if (retval==LL_NORMAL) return retval;
1428 } 1434 }
1429 LOG(llevDebug,"Got eof while scanning strings\n"); 1435 LOG(llevDebug,"Got eof while scanning strings\n");
1430 return LL_EOF; 1436 return LL_EOF;
1431 } 1437 }
1432 1438
1433 retval=lex_load(op, map_flags); 1439 retval=lex_load(op, thawer, map_flags);
1434 if (op->current_weapon_script != NULL) 1440 if (op->current_weapon_script != NULL)
1435 { 1441 {
1436 op->current_weapon = find_best_weapon_used_match(op, op->current_weapon_script); 1442 op->current_weapon = find_best_weapon_used_match(op, op->current_weapon_script);
1437 LOG(llevDebug, "CurrentWeapon Loaded !\n"); 1443 LOG(llevDebug, "CurrentWeapon Loaded !\n");
1438 }; 1444 };
1449 * override values and in c_wiz to mutate values. 1455 * override values and in c_wiz to mutate values.
1450 */ 1456 */
1451int set_variable(object *op,char *buf) { 1457int set_variable(object *op,char *buf) {
1452 YY_BUFFER_STATE yybufstate,yycurbuf=YY_CURRENT_BUFFER; 1458 YY_BUFFER_STATE yybufstate,yycurbuf=YY_CURRENT_BUFFER;
1453 int retval; 1459 int retval;
1460 object_thawer thawer;
1454 1461
1455 strcpy(msgbuf, ""); 1462 strcpy(msgbuf, "");
1456 strcpy(lorebuf, ""); 1463 strcpy(lorebuf, "");
1457 yy_push_state(INITIAL); 1464 yy_push_state(INITIAL);
1458 yybufstate=yy_scan_string(buf); 1465 yybufstate=yy_scan_string(buf);
1459 retval=lex_load(op,0); 1466 retval=lex_load(op,thawer,0);
1460 yy_switch_to_buffer(yycurbuf); 1467 yy_switch_to_buffer(yycurbuf);
1461 yy_delete_buffer(yybufstate); 1468 yy_delete_buffer(yybufstate);
1462 yy_pop_state(); 1469 yy_pop_state();
1463 return retval; 1470 return retval;
1464} 1471}
2031 * the only place this is not set is when saving the player. 2038 * the only place this is not set is when saving the player.
2032 * If bit 1 of flag is set, don't remove the object after save. As of now, 2039 * If bit 1 of flag is set, don't remove the object after save. As of now,
2033 * all of the callers are setting this. 2040 * all of the callers are setting this.
2034 */ 2041 */
2035 2042
2036void save_object(FILE *fp,object *op, int flag) { 2043void save_object(FILE *fp,object_freezer &freezer,object *op, int flag) {
2037 archetype *at; 2044 archetype *at;
2038 char *cp; 2045 char *cp;
2039 object *tmp,*old; 2046 object *tmp,*old;
2040 2047
2041 /* Even if the object does have an owner, it would seem that we should 2048 /* Even if the object does have an owner, it would seem that we should
2059 2066
2060 old=NULL; 2067 old=NULL;
2061 2068
2062 if (flag & 2 ) 2069 if (flag & 2 )
2063 for(tmp=op->inv;tmp!=NULL;tmp=tmp->below) 2070 for(tmp=op->inv;tmp!=NULL;tmp=tmp->below)
2064 save_object(fp,tmp,flag); 2071 save_object(fp,freezer,tmp,flag);
2065 2072
2066 /* Slightly different logic because tmp/op will be removed by 2073 /* Slightly different logic because tmp/op will be removed by
2067 * the save_object we call. So we just keep looking at op->inv 2074 * the save_object we call. So we just keep looking at op->inv
2068 * until there is nothing left. In theory, the variable old 2075 * until there is nothing left. In theory, the variable old
2069 * should not be needed, as recursive loops shouldn't happen. 2076 * should not be needed, as recursive loops shouldn't happen.
2071 else while ((tmp=op->inv)!=NULL) { 2078 else while ((tmp=op->inv)!=NULL) {
2072 if(old==tmp) { 2079 if(old==tmp) {
2073 LOG(llevError," Recursive loop in inventory\n"); 2080 LOG(llevError," Recursive loop in inventory\n");
2074 break; 2081 break;
2075 } 2082 }
2076 save_object(fp,tmp,flag); 2083 save_object(fp,freezer,tmp,flag);
2077 old=tmp; 2084 old=tmp;
2078 } 2085 }
2079 2086
2080 if (!(flag&2)) { 2087 if (!(flag&2)) {
2081 remove_ob(op); 2088 remove_ob(op);
2082 free_object (op); 2089 free_object (op);
2083 } 2090 }
2084 2091
2085 fprintf(fp,"end\n"); 2092 fprintf(fp,"end\n");
2093 freezer.put (op);
2086} 2094}
2087 2095
2088void insert_event(object* op, int etype, char *ehook, char *eplug, char *eoptions) 2096void insert_event(object* op, int etype, char *ehook, char *eplug, char *eoptions)
2089{ 2097{
2090 event *evt; 2098 event *evt;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines