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.1.1.2 by elmex, Wed Feb 22 18:01:20 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.1.1.2 2006/02/22 18:01:20 elmex 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[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 */
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.
333static 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
353static 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 }
733 */ 769 */
734 ismore=1; 770 ismore=1;
735 } 771 }
736 772
737^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
738 if (ismore) return LL_MORE; 781 if (ismore) return LL_MORE;
739 else return LL_NORMAL; 782 else return LL_NORMAL;
740 } 783 }
741^last_heal{S} op->last_heal = IVAL; 784^last_heal{S} op->last_heal = IVAL;
742^last_sp{S} op->last_sp = IVAL; 785^last_sp{S} op->last_sp = IVAL;
834^neutral{S} SET_OR_CLEAR_FLAG(op, FLAG_NEUTRAL, IVAL); 877^neutral{S} SET_OR_CLEAR_FLAG(op, FLAG_NEUTRAL, IVAL);
835^no_attack{S} SET_OR_CLEAR_FLAG(op, FLAG_NO_ATTACK, IVAL); 878^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); 879^no_damage{S} SET_OR_CLEAR_FLAG(op, FLAG_NO_DAMAGE, IVAL);
837^friendly{S} { if (IVAL) { 880^friendly{S} { if (IVAL) {
838 SET_FLAG(op, FLAG_FRIENDLY); 881 SET_FLAG(op, FLAG_FRIENDLY);
839 if (op->type != PLAYER) { 882 if (op->type != PLAYER)
840 LOG(llevDebug," Adding friendly object %s.\n",op->name);
841 add_friendly_object(op); 883 add_friendly_object (op);
842 }
843 } 884 }
844 else CLEAR_FLAG(op, FLAG_FRIENDLY); 885 else CLEAR_FLAG(op, FLAG_FRIENDLY);
845 } 886 }
846^generator{S} SET_OR_CLEAR_FLAG(op, FLAG_GENERATOR, IVAL); 887^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); 888^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); 996^resist_disease{S} SET_RESIST(op, ATNR_DISEASE, IVAL);
956 997
957 /* Old style resistances */ 998 /* Old style resistances */
958^immune{S} set_protection(op, IVAL, RESIST_IMMUNE); 999^immune{S} set_protection(op, IVAL, RESIST_IMMUNE);
959^protected{S} set_protection(op, IVAL, RESIST_PROT); 1000^protected{S} set_protection(op, IVAL, RESIST_PROT);
960^vulnerable{S} set_protection(op, IVAL, RESIST_VULN); 1001^vulnerable{S} set_protection(op, IVAL, (uint16) RESIST_VULN);
961 1002
962 /* old values - keep them around for now, but they should be removed at some point */ 1003 /* 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); 1004^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); 1005^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); 1006^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 */ } 1045^can_impale{S} { /* That these are for the new combat code */ }
1005^can_cut{S} { /* just ignore for now */ } 1046^can_cut{S} { /* just ignore for now */ }
1006^can_dam_armour{S} { } 1047^can_dam_armour{S} { }
1007^weapontype{S} op->weapontype = IVAL; 1048^weapontype{S} op->weapontype = IVAL;
1008^tooltype{S} op->tooltype = IVAL; 1049^tooltype{S} op->tooltype = IVAL;
1009^casting_time{S} op->casting_time = FVAL; 1050^casting_time{S} op->casting_time = (sint16) FVAL;
1010^elevation{S} op->elevation = IVAL; 1051^elevation{S} op->elevation = IVAL;
1011^smoothlevel{S} op->smoothlevel = IVAL; 1052^smoothlevel{S} op->smoothlevel = IVAL;
1012^client_type{S} op->client_type = IVAL; 1053^client_type{S} op->client_type = IVAL;
1013^body_{A} set_body_info(op, yytext); 1054^body_{A} set_body_info(op, yytext);
1014^duration{S} op->duration = IVAL; 1055^duration{S} op->duration = IVAL;
1369 * be reset. 1410 * be reset.
1370 * 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)
1371 * 1412 *
1372 */ 1413 */
1373 1414
1374int 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) {
1375 int retval; 1416 int retval;
1376 char inbuf[MAX_BUF]; 1417 char inbuf[MAX_BUF];
1377 1418
1378 strcpy(msgbuf, ""); 1419 strcpy(msgbuf, "");
1379 strcpy(lorebuf, ""); 1420 strcpy(lorebuf, "");
1385 } 1426 }
1386 if (bufstate==LO_LINEMODE) { 1427 if (bufstate==LO_LINEMODE) {
1387 YY_BUFFER_STATE yybufstate; 1428 YY_BUFFER_STATE yybufstate;
1388 while (fgets(inbuf, MAX_BUF-3, fp)) { 1429 while (fgets(inbuf, MAX_BUF-3, fp)) {
1389 yybufstate=yy_scan_string(inbuf); 1430 yybufstate=yy_scan_string(inbuf);
1390 retval=lex_load(op, map_flags); 1431 retval=lex_load(op, thawer, map_flags);
1391 yy_delete_buffer(yybufstate); 1432 yy_delete_buffer(yybufstate);
1392 if (retval==LL_NORMAL) return retval; 1433 if (retval==LL_NORMAL) return retval;
1393 } 1434 }
1394 LOG(llevDebug,"Got eof while scanning strings\n"); 1435 LOG(llevDebug,"Got eof while scanning strings\n");
1395 return LL_EOF; 1436 return LL_EOF;
1396 } 1437 }
1397 1438
1398 retval=lex_load(op, map_flags); 1439 retval=lex_load(op, thawer, map_flags);
1399 if (op->current_weapon_script != NULL) 1440 if (op->current_weapon_script != NULL)
1400 { 1441 {
1401 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);
1402 LOG(llevDebug, "CurrentWeapon Loaded !\n"); 1443 LOG(llevDebug, "CurrentWeapon Loaded !\n");
1403 }; 1444 };
1414 * override values and in c_wiz to mutate values. 1455 * override values and in c_wiz to mutate values.
1415 */ 1456 */
1416int set_variable(object *op,char *buf) { 1457int set_variable(object *op,char *buf) {
1417 YY_BUFFER_STATE yybufstate,yycurbuf=YY_CURRENT_BUFFER; 1458 YY_BUFFER_STATE yybufstate,yycurbuf=YY_CURRENT_BUFFER;
1418 int retval; 1459 int retval;
1460 object_thawer thawer;
1419 1461
1420 strcpy(msgbuf, ""); 1462 strcpy(msgbuf, "");
1421 strcpy(lorebuf, ""); 1463 strcpy(lorebuf, "");
1422 yy_push_state(INITIAL); 1464 yy_push_state(INITIAL);
1423 yybufstate=yy_scan_string(buf); 1465 yybufstate=yy_scan_string(buf);
1424 retval=lex_load(op,0); 1466 retval=lex_load(op,thawer,0);
1425 yy_switch_to_buffer(yycurbuf); 1467 yy_switch_to_buffer(yycurbuf);
1426 yy_delete_buffer(yybufstate); 1468 yy_delete_buffer(yybufstate);
1427 yy_pop_state(); 1469 yy_pop_state();
1428 return retval; 1470 return retval;
1429} 1471}
1545 1587
1546 strcpy(retbuf,""); 1588 strcpy(retbuf,"");
1547 strcpy(retbuf_all," all"); 1589 strcpy(retbuf_all," all");
1548 1590
1549 /* Quick check, and probably fairly common */ 1591 /* Quick check, and probably fairly common */
1550 if (mt == MOVE_ALL) return retbuf_all; 1592 if (mt == MOVE_ALL) return retbuf_all+1;
1551 if (mt == 0) { 1593 if (mt == 0) {
1552 strcpy(retbuf,"0"); 1594 strcpy(retbuf,"0");
1553 return retbuf; 1595 return retbuf;
1554 } 1596 }
1555 1597
1570 /* Basically, if there is a single negation, return it, eg 1612 /* Basically, if there is a single negation, return it, eg
1571 * 'all -swim'. But more than that, just return the 1613 * 'all -swim'. But more than that, just return the
1572 * enumerated values. It doesn't make sense to return 1614 * enumerated values. It doesn't make sense to return
1573 * 'all -walk -fly_low' - it is shorter to return 'fly_high swim' 1615 * 'all -walk -fly_low' - it is shorter to return 'fly_high swim'
1574 */ 1616 */
1575 if (all_count <=1) return retbuf_all; 1617 if (all_count <=1) return retbuf_all+1;
1576 else return retbuf; 1618 else return retbuf+1;
1577} 1619}
1578 1620
1579 1621
1580/* 1622/*
1581 * Returns a pointer to a static string which contains all variables 1623 * Returns a pointer to a static string which contains all variables
1618 * NEVER touch buf between PREPARE_FASTCAT(buf) and 1660 * NEVER touch buf between PREPARE_FASTCAT(buf) and
1619 * FINISH_FASTCAT(buf) 1661 * FINISH_FASTCAT(buf)
1620 */ 1662 */
1621 static int already_run = 0; 1663 static int already_run = 0;
1622 static int flag_lens[NUM_FLAGS]; 1664 static int flag_lens[NUM_FLAGS];
1623 static char buf2[HUGE_BUF]; 1665 char buf2[4096]; // / was HUFE_BUF, which was hugely incorrect, as is this value, but much less so
1624 static char buf[HUGE_BUF]; 1666 static char buf[128*1024]; // < the assumption is that every object always fits. fixing this bug, however
1625 char* fastbuf; 1667 char* fastbuf; // \ requires a large rewrite of the code, so its left to the next total rewrite.
1626 int tmp; 1668 int tmp;
1627 int i; 1669 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; 1670 event *etmp;
1635 event *etmp2; 1671 event *etmp2;
1636 key_value * my_field; 1672 key_value * my_field;
1637 key_value * arch_field; 1673 key_value * arch_field;
1638 1674
1767 if(op->stats.maxgrace!=op2->stats.maxgrace) 1803 if(op->stats.maxgrace!=op2->stats.maxgrace)
1768 FAST_SAVE_LONG(fastbuf,"maxgrace ",op->stats.maxgrace,9); 1804 FAST_SAVE_LONG(fastbuf,"maxgrace ",op->stats.maxgrace,9);
1769 1805
1770 if(op->stats.exp!=op2->stats.exp) { 1806 if(op->stats.exp!=op2->stats.exp) {
1771#ifndef WIN32 1807#ifndef WIN32
1772 sprintf(buf2,"%lld\n", op->stats.exp); 1808 sprintf(buf2,"%lld", op->stats.exp);
1773#else 1809#else
1774 sprintf(buf2,"%I64d\n", op->stats.exp); 1810 sprintf(buf2,"%I64d", op->stats.exp);
1775#endif 1811#endif
1776 ADD_STRINGLINE_ENTRY(fastbuf,"exp ", buf2, 4); 1812 ADD_STRINGLINE_ENTRY(fastbuf,"exp ", buf2, 4);
1777 } 1813 }
1778 1814
1779 if(op->perm_exp!=op2->perm_exp) { 1815 if(op->perm_exp!=op2->perm_exp) {
1780#ifndef WIN32 1816#ifndef WIN32
1781 sprintf(buf2,"%lld\n", op->perm_exp); 1817 sprintf(buf2,"%lld", op->perm_exp);
1782#else 1818#else
1783 sprintf(buf2,"%I64d\n", op->perm_exp); 1819 sprintf(buf2,"%I64d", op->perm_exp);
1784#endif 1820#endif
1785 ADD_STRINGLINE_ENTRY(fastbuf,"perm_exp ", buf2, 9); 1821 ADD_STRINGLINE_ENTRY(fastbuf,"perm_exp ", buf2, 9);
1786 } 1822 }
1787 1823
1788 if(op->expmul!=op2->expmul) 1824 if(op->expmul!=op2->expmul)
1933 * save (say to a temp map, where we don't care about strings), 1969 * 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. 1970 * or a slower save/dm dump, where printing out strings is handy.
1935 */ 1971 */
1936 if (op->move_type != op2->move_type) { 1972 if (op->move_type != op2->move_type) {
1937 /*FAST_SAVE_LONG(fastbuf,"move_type ",op->move_type,10)*/ 1973 /*FAST_SAVE_LONG(fastbuf,"move_type ",op->move_type,10)*/
1938 ADD_STRINGLINE_ENTRY(fastbuf,"move_type ", 1974 ADD_STRINGLINE_ENTRY(fastbuf,"move_type ",
1939 get_string_move_type(op->move_type), 1975 get_string_move_type(op->move_type),
1940 10); 1976 10);
1941 } 1977 }
1942 if (op->move_block != op2->move_block) { 1978 if (op->move_block != op2->move_block) {
1943 /*FAST_SAVE_LONG(fastbuf,"move_block ",op->move_block,11)*/ 1979 /*FAST_SAVE_LONG(fastbuf,"move_block ",op->move_block,11)*/
1944 ADD_STRINGLINE_ENTRY(fastbuf,"move_block ", 1980 ADD_STRINGLINE_ENTRY(fastbuf,"move_block ",
1945 get_string_move_type(op->move_block), 1981 get_string_move_type(op->move_block),
1946 11); 1982 11);
1947 } 1983 }
1948 if (op->move_allow != op2->move_allow) { 1984 if (op->move_allow != op2->move_allow) {
1949 /*FAST_SAVE_LONG(fastbuf,"move_allow ",op->move_allow,11);*/ 1985 /*FAST_SAVE_LONG(fastbuf,"move_allow ",op->move_allow,11);*/
1950 ADD_STRINGLINE_ENTRY(fastbuf,"move_allow ", 1986 ADD_STRINGLINE_ENTRY(fastbuf,"move_allow ",
1951 get_string_move_type(op->move_allow), 1987 get_string_move_type(op->move_allow),
1952 11); 1988 11);
1953 } 1989 }
1954 if (op->move_on != op2->move_on) { 1990 if (op->move_on != op2->move_on) {
1955 /*FAST_SAVE_LONG(fastbuf,"move_on ",op->move_on,8);*/ 1991 /*FAST_SAVE_LONG(fastbuf,"move_on ",op->move_on,8);*/
1956 ADD_STRINGLINE_ENTRY(fastbuf,"move_on ", 1992 ADD_STRINGLINE_ENTRY(fastbuf,"move_on ",
1957 get_string_move_type(op->move_on), 1993 get_string_move_type(op->move_on),
1958 8); 1994 8);
1959 } 1995 }
1960 if (op->move_off != op2->move_off) { 1996 if (op->move_off != op2->move_off) {
1961 /*FAST_SAVE_LONG(fastbuf,"move_off ",op->move_off,9);*/ 1997 /*FAST_SAVE_LONG(fastbuf,"move_off ",op->move_off,9);*/
1962 ADD_STRINGLINE_ENTRY(fastbuf,"move_off ", 1998 ADD_STRINGLINE_ENTRY(fastbuf,"move_off ",
1963 get_string_move_type(op->move_off), 1999 get_string_move_type(op->move_off),
1964 9); 2000 9);
1965 } 2001 }
1966 if (op->move_slow != op2->move_slow) { 2002 if (op->move_slow != op2->move_slow) {
1967 /*FAST_SAVE_LONG(fastbuf,"move_slow ",op->move_slow,10);*/ 2003 /*FAST_SAVE_LONG(fastbuf,"move_slow ",op->move_slow,10);*/
1968 ADD_STRINGLINE_ENTRY(fastbuf,"move_slow ", 2004 ADD_STRINGLINE_ENTRY(fastbuf,"move_slow ",
1969 get_string_move_type(op->move_slow), 2005 get_string_move_type(op->move_slow),
1970 10); 2006 10);
1971 } 2007 }
1972 2008
1973 if (op->move_slow_penalty != op2->move_slow_penalty) { 2009 if (op->move_slow_penalty != op2->move_slow_penalty) {
1974 FAST_SAVE_LONG(fastbuf,"move_slow_penalty ",op->move_slow_penalty,18); 2010 FAST_SAVE_LONG(fastbuf,"move_slow_penalty ",(long) op->move_slow_penalty,18);
1975 } 2011 }
1976 2012
1977 if (!COMPARE_FLAGS(op,op2)) { 2013 if (!COMPARE_FLAGS(op,op2)) {
1978 for (tmp=0; tmp <= NUM_FLAGS; tmp++) { 2014 for (tmp=0; tmp <= NUM_FLAGS; tmp++) {
1979 if (flag_names[tmp] && (QUERY_FLAG(op, tmp) != QUERY_FLAG(op2, tmp))) { 2015 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. 2038 * 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, 2039 * 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. 2040 * all of the callers are setting this.
2005 */ 2041 */
2006 2042
2007void save_object(FILE *fp,object *op, int flag) { 2043void save_object(FILE *fp,object_freezer &freezer,object *op, int flag) {
2008 archetype *at; 2044 archetype *at;
2009 char *cp; 2045 char *cp;
2010 object *tmp,*old; 2046 object *tmp,*old;
2011 2047
2012 /* 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
2030 2066
2031 old=NULL; 2067 old=NULL;
2032 2068
2033 if (flag & 2 ) 2069 if (flag & 2 )
2034 for(tmp=op->inv;tmp!=NULL;tmp=tmp->below) 2070 for(tmp=op->inv;tmp!=NULL;tmp=tmp->below)
2035 save_object(fp,tmp,flag); 2071 save_object(fp,freezer,tmp,flag);
2036 2072
2037 /* Slightly different logic because tmp/op will be removed by 2073 /* Slightly different logic because tmp/op will be removed by
2038 * 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
2039 * until there is nothing left. In theory, the variable old 2075 * until there is nothing left. In theory, the variable old
2040 * should not be needed, as recursive loops shouldn't happen. 2076 * should not be needed, as recursive loops shouldn't happen.
2042 else while ((tmp=op->inv)!=NULL) { 2078 else while ((tmp=op->inv)!=NULL) {
2043 if(old==tmp) { 2079 if(old==tmp) {
2044 LOG(llevError," Recursive loop in inventory\n"); 2080 LOG(llevError," Recursive loop in inventory\n");
2045 break; 2081 break;
2046 } 2082 }
2047 save_object(fp,tmp,flag); 2083 save_object(fp,freezer,tmp,flag);
2048 old=tmp; 2084 old=tmp;
2049 } 2085 }
2050 2086
2051 if (!(flag&2)) { 2087 if (!(flag&2)) {
2052 remove_ob(op); 2088 remove_ob(op);
2053 free_object (op); 2089 free_object (op);
2054 } 2090 }
2055 2091
2056 fprintf(fp,"end\n"); 2092 fprintf(fp,"end\n");
2093 freezer.put (op);
2057} 2094}
2058 2095
2059void 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)
2060{ 2097{
2061 event *evt; 2098 event *evt;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines