1 | %{ |
1 | %{ |
2 | /* |
2 | /* |
3 | * static char *rcsid_object_c = |
3 | * static char *rcsid_object_c = |
4 | * "$Id: loader.l,v 1.10 2006/08/27 16:15:11 root 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 | |
… | |
… | |
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 | } |
… | |
… | |
768 | ^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, |
769 | * so the calling function can glue things back together |
768 | * so the calling function can glue things back together |
770 | */ |
769 | */ |
771 | ismore=1; |
770 | ismore=1; |
772 | } |
771 | } |
773 | |
|
|
774 | ^end{WS}$ { check_loaded_object(op); |
772 | ^end{WS}$ { check_loaded_object(op); |
775 | thawer.get (op); |
773 | |
|
|
774 | if (!arch_init) |
|
|
775 | op->instantiate (); |
|
|
776 | |
776 | if (ismore) return LL_MORE; |
777 | if (ismore) return LL_MORE; |
777 | else return LL_NORMAL; |
778 | else return LL_NORMAL; |
778 | } |
779 | } |
|
|
780 | ^oid{S} { |
|
|
781 | thawer.get (op, IVAL); |
|
|
782 | } |
779 | ^last_heal{S} op->last_heal = IVAL; |
783 | ^last_heal{S} op->last_heal = IVAL; |
780 | ^last_sp{S} op->last_sp = IVAL; |
784 | ^last_sp{S} op->last_sp = IVAL; |
781 | ^last_grace{S} op->last_grace = IVAL; |
785 | ^last_grace{S} op->last_grace = IVAL; |
782 | ^last_eat{S} op->last_eat = IVAL; |
786 | ^last_eat{S} op->last_eat = IVAL; |
783 | ^speed{S} { op->speed = FVAL; |
787 | ^speed{S} { op->speed = FVAL; |
… | |
… | |
1405 | * be reset. |
1409 | * be reset. |
1406 | * 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) |
1407 | * |
1411 | * |
1408 | */ |
1412 | */ |
1409 | |
1413 | |
1410 | int load_object(FILE *fp, object_thawer &thawer, object *op, int bufstate, int map_flags) { |
1414 | int load_object(object_thawer &fp, object *op, int bufstate, int map_flags) { |
1411 | int retval; |
1415 | int retval; |
1412 | char inbuf[MAX_BUF]; |
1416 | char inbuf[MAX_BUF]; |
1413 | |
1417 | |
1414 | strcpy(msgbuf, ""); |
1418 | strcpy(msgbuf, ""); |
1415 | strcpy(lorebuf, ""); |
1419 | strcpy(lorebuf, ""); |
… | |
… | |
1421 | } |
1425 | } |
1422 | if (bufstate==LO_LINEMODE) { |
1426 | if (bufstate==LO_LINEMODE) { |
1423 | YY_BUFFER_STATE yybufstate; |
1427 | YY_BUFFER_STATE yybufstate; |
1424 | while (fgets(inbuf, MAX_BUF-3, fp)) { |
1428 | while (fgets(inbuf, MAX_BUF-3, fp)) { |
1425 | yybufstate=yy_scan_string(inbuf); |
1429 | yybufstate=yy_scan_string(inbuf); |
1426 | retval=lex_load(op, thawer, map_flags); |
1430 | retval=lex_load(op, fp, map_flags); |
1427 | yy_delete_buffer(yybufstate); |
1431 | yy_delete_buffer(yybufstate); |
1428 | if (retval==LL_NORMAL) return retval; |
1432 | if (retval==LL_NORMAL) return retval; |
1429 | } |
1433 | } |
1430 | LOG(llevDebug,"Got eof while scanning strings\n"); |
1434 | LOG(llevDebug,"Got eof while scanning strings\n"); |
1431 | return LL_EOF; |
1435 | return LL_EOF; |
1432 | } |
1436 | } |
1433 | |
1437 | |
1434 | retval=lex_load(op, thawer, map_flags); |
1438 | retval=lex_load(op, fp, map_flags); |
1435 | if (op->current_weapon_script != NULL) |
1439 | if (op->current_weapon_script != NULL) |
1436 | { |
1440 | { |
1437 | 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); |
1438 | LOG(llevDebug, "CurrentWeapon Loaded !\n"); |
1442 | LOG(llevDebug, "CurrentWeapon Loaded !\n"); |
1439 | }; |
1443 | }; |
… | |
… | |
1450 | * override values and in c_wiz to mutate values. |
1454 | * override values and in c_wiz to mutate values. |
1451 | */ |
1455 | */ |
1452 | int set_variable(object *op,char *buf) { |
1456 | int set_variable(object *op,char *buf) { |
1453 | YY_BUFFER_STATE yybufstate,yycurbuf=YY_CURRENT_BUFFER; |
1457 | YY_BUFFER_STATE yybufstate,yycurbuf=YY_CURRENT_BUFFER; |
1454 | int retval; |
1458 | int retval; |
1455 | object_thawer thawer; |
1459 | object_thawer thawer (0); |
1456 | |
1460 | |
1457 | strcpy(msgbuf, ""); |
1461 | strcpy(msgbuf, ""); |
1458 | strcpy(lorebuf, ""); |
1462 | strcpy(lorebuf, ""); |
1459 | yy_push_state(INITIAL); |
1463 | yy_push_state(INITIAL); |
1460 | yybufstate=yy_scan_string(buf); |
1464 | yybufstate=yy_scan_string(buf); |
… | |
… | |
2033 | * 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. |
2034 | * 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, |
2035 | * all of the callers are setting this. |
2039 | * all of the callers are setting this. |
2036 | */ |
2040 | */ |
2037 | |
2041 | |
2038 | void save_object(FILE *fp,object_freezer &freezer,object *op, int flag) { |
2042 | void save_object(object_freezer &fp,object *op, int flag) { |
2039 | archetype *at; |
2043 | archetype *at; |
2040 | char *cp; |
2044 | char *cp; |
2041 | object *tmp,*old; |
2045 | object *tmp,*old; |
2042 | |
2046 | |
2043 | /* 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 |
… | |
… | |
2061 | |
2065 | |
2062 | old=NULL; |
2066 | old=NULL; |
2063 | |
2067 | |
2064 | if (flag & 2 ) |
2068 | if (flag & 2 ) |
2065 | for(tmp=op->inv;tmp!=NULL;tmp=tmp->below) |
2069 | for(tmp=op->inv;tmp!=NULL;tmp=tmp->below) |
2066 | save_object(fp,freezer,tmp,flag); |
2070 | save_object(fp,tmp,flag); |
2067 | |
2071 | |
2068 | /* Slightly different logic because tmp/op will be removed by |
2072 | /* Slightly different logic because tmp/op will be removed by |
2069 | * 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 |
2070 | * until there is nothing left. In theory, the variable old |
2074 | * until there is nothing left. In theory, the variable old |
2071 | * should not be needed, as recursive loops shouldn't happen. |
2075 | * should not be needed, as recursive loops shouldn't happen. |
… | |
… | |
2073 | else while ((tmp=op->inv)!=NULL) { |
2077 | else while ((tmp=op->inv)!=NULL) { |
2074 | if(old==tmp) { |
2078 | if(old==tmp) { |
2075 | LOG(llevError," Recursive loop in inventory\n"); |
2079 | LOG(llevError," Recursive loop in inventory\n"); |
2076 | break; |
2080 | break; |
2077 | } |
2081 | } |
2078 | save_object(fp,freezer,tmp,flag); |
2082 | save_object(fp,tmp,flag); |
2079 | old=tmp; |
2083 | old=tmp; |
2080 | } |
2084 | } |
2081 | |
2085 | |
2082 | if (!(flag&2)) { |
2086 | if (!(flag&2)) { |
2083 | remove_ob(op); |
2087 | remove_ob(op); |
2084 | free_object (op); |
2088 | free_object (op); |
2085 | } |
2089 | } |
2086 | |
2090 | |
|
|
2091 | fp.put (op); |
2087 | fprintf(fp,"end\n"); |
2092 | fprintf(fp,"end\n"); |
2088 | freezer.put (op); |
|
|
2089 | } |
2093 | } |
2090 | |
2094 | |
2091 | 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) |
2092 | { |
2096 | { |
2093 | event *evt; |
2097 | event *evt; |