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 by root, Fri Feb 3 07:11:36 2006 UTC vs.
Revision 1.2 by root, Thu May 11 18:37:20 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 2006/02/03 07:11:36 root Exp $"; 4 * "$Id: loader.l,v 1.2 2006/05/11 18:37:20 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
42static char *yval(); 42static char *yval();
43 43
44static int lex_error; 44static int lex_error;
45static char msgbuf[HUGE_BUF]; 45static char msgbuf[HUGE_BUF];
46static char lorebuf[HUGE_BUF]; 46static char lorebuf[HUGE_BUF];
47
48/* Maps the MOVE_* values to names */
49static const char *const move_name[] = {"walk", "fly_low", "fly_high", "swim", "boat",
50 NULL};
47 51
48/* This table is only necessary to convert objects that existed before the 52/* This table is only necessary to convert objects that existed before the
49 * spell object conversion to the new object. It was not practical 53 * spell object conversion to the new object. It was not practical
50 * to go through every mapping looking for every potion, rod, wand, etc 54 * to go through every mapping looking for every potion, rod, wand, etc
51 * that had a sp set and update to the new value. So this maps the 55 * that had a sp set and update to the new value. So this maps the
53 * 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
54 * 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.
55 * 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
56 * not be updated for whatever reason. 60 * not be updated for whatever reason.
57 */ 61 */
58char *spell_mapping[] = { 62const char *const spell_mapping[] = {
59"spell_magic_bullet", /* 0 */ 63"spell_magic_bullet", /* 0 */
60"spell_small_fireball", /* 1 */ 64"spell_small_fireball", /* 1 */
61"spell_medium_fireball", /* 2 */ 65"spell_medium_fireball", /* 2 */
62"spell_large_fireball", /* 3 */ 66"spell_large_fireball", /* 3 */
63"spell_burning_hands", /* 4 */ 67"spell_burning_hands", /* 4 */
535 *end='\0'; 539 *end='\0';
536 } 540 }
537 set_ob_key_value(op, key, value, TRUE); 541 set_ob_key_value(op, key, value, TRUE);
538} 542}
539 543
544static void set_move(MoveType *mt, char *params) {
545 char *str;
546 int i, negate;
547
548 if (isdigit(*params)) {
549 *mt = atoi(params);
550 } else {
551 *mt=0;
552 for (str=strtok(params, " "); str; str=strtok(NULL, " ")) {
553 negate=0;
554 if (!strcasecmp(str, "all"))
555 *mt |= MOVE_ALL;
556 else {
557 if (*str=='-') {
558 negate = 1;
559 str++;
560 }
561 for (i=0; move_name[i] != NULL; i++) {
562 if (!strcasecmp(move_name[i], str)) {
563 if (negate) {
564 *mt &= ~(1<<i);
565 } else {
566 *mt |= (1<<i);
567 }
568 break;
569 }
570 }
571 if (move_name[i] == NULL) {
572 /* fly is a special case - covers both fly_low and
573 * fly_high - since it doesn't match to a specific
574 * single bit, have to special case it.
575 */
576 if (!strcasecmp(str,"flying")) {
577 if (negate) {
578 *mt &= ~MOVE_FLYING;
579 } else {
580 *mt |= MOVE_FLYING;
581 }
582 } else {
583 LOG(llevDebug, "common/loader.l: set_move - unknown move string '%s'\n", str);
584 }
585 }
586 } /* Else not all move types */
587 } /* for strtok */
588 } /* Else not a numeric value */
589}
540 590
541%} 591%}
542 592
543 593
544 594
769^fly_off{S} { if (IVAL) op->move_off |= MOVE_FLY_LOW; else op->move_off &= ~MOVE_FLY_LOW; } 819^fly_off{S} { if (IVAL) op->move_off |= MOVE_FLY_LOW; else op->move_off &= ~MOVE_FLY_LOW; }
770^flying{S} { if (IVAL) op->move_type |= MOVE_FLY_LOW; else op->move_type &= ~MOVE_FLY_LOW; } 820^flying{S} { if (IVAL) op->move_type |= MOVE_FLY_LOW; else op->move_type &= ~MOVE_FLY_LOW; }
771 821
772%{ /* These are the new values */ 822%{ /* These are the new values */
773%} 823%}
774^move_block{S} op->move_block = IVAL; 824^move_block{S} set_move(&op->move_block, yval());
775^move_type{S} op->move_type = IVAL; 825^move_allow{S} set_move(&op->move_allow, yval());
776^move_on{S} op->move_on = IVAL; 826^move_type{S} set_move(&op->move_type, yval());
777^move_off{S} op->move_off = IVAL; 827^move_on{S} set_move(&op->move_on, yval());
778^move_slow{S} op->move_slow = IVAL; 828^move_off{S} set_move(&op->move_off, yval());
829^move_slow{S} set_move(&op->move_slow, yval());
779^move_slow_penalty{S} op->move_slow_penalty = FVAL; 830^move_slow_penalty{S} op->move_slow_penalty = FVAL;
780 831
781 832
782^monster{S} SET_OR_CLEAR_FLAG(op, FLAG_MONSTER, IVAL); 833^monster{S} SET_OR_CLEAR_FLAG(op, FLAG_MONSTER, IVAL);
783^neutral{S} SET_OR_CLEAR_FLAG(op, FLAG_NEUTRAL, IVAL); 834^neutral{S} SET_OR_CLEAR_FLAG(op, FLAG_NEUTRAL, IVAL);
784^no_attack{S} SET_OR_CLEAR_FLAG(op, FLAG_NO_ATTACK, IVAL); 835^no_attack{S} SET_OR_CLEAR_FLAG(op, FLAG_NO_ATTACK, IVAL);
785^no_damage{S} SET_OR_CLEAR_FLAG(op, FLAG_NO_DAMAGE, IVAL); 836^no_damage{S} SET_OR_CLEAR_FLAG(op, FLAG_NO_DAMAGE, IVAL);
786^friendly{S} { if (IVAL) { 837^friendly{S} { if (IVAL) {
787 SET_FLAG(op, FLAG_FRIENDLY); 838 SET_FLAG(op, FLAG_FRIENDLY);
788 if (op->type != PLAYER) { 839 if (op->type != PLAYER)
789 LOG(llevDebug," Adding friendly object %s.\n",op->name);
790 add_friendly_object(op); 840 add_friendly_object (op);
791 }
792 } 841 }
793 else CLEAR_FLAG(op, FLAG_FRIENDLY); 842 else CLEAR_FLAG(op, FLAG_FRIENDLY);
794 } 843 }
795^generator{S} SET_OR_CLEAR_FLAG(op, FLAG_GENERATOR, IVAL); 844^generator{S} SET_OR_CLEAR_FLAG(op, FLAG_GENERATOR, IVAL);
796^use_content_on_gen{S} SET_OR_CLEAR_FLAG (op,FLAG_CONTENT_ON_GEN, IVAL); 845^use_content_on_gen{S} SET_OR_CLEAR_FLAG (op,FLAG_CONTENT_ON_GEN, IVAL);
1386/* This is a list of pointers that correspond to the FLAG_.. values. 1435/* This is a list of pointers that correspond to the FLAG_.. values.
1387 * This is a simple 1:1 mapping - if FLAG_FRIENDLY is 15, then 1436 * This is a simple 1:1 mapping - if FLAG_FRIENDLY is 15, then
1388 * the 15'th element of this array should match that name. 1437 * the 15'th element of this array should match that name.
1389 * If an entry is NULL, that is a flag not to loaded/saved. 1438 * If an entry is NULL, that is a flag not to loaded/saved.
1390 */ 1439 */
1391static char *flag_names[NUM_FLAGS+1] = { 1440static const char *const flag_names[NUM_FLAGS+1] = {
1392"alive", "wiz", NULL, NULL, "was_wiz", "applied", "unpaid", 1441"alive", "wiz", NULL, NULL, "was_wiz", "applied", "unpaid",
1393"can_use_shield", "no_pick", NULL /* walk_on*/, NULL /* no_pass */, /* 10 */ 1442"can_use_shield", "no_pick", NULL /* walk_on*/, NULL /* no_pass */, /* 10 */
1394"is_animated", NULL /* slow_move */, 1443"is_animated", NULL /* slow_move */,
1395NULL /* flying */, "monster", "friendly", "generator", 1444NULL /* flying */, "monster", "friendly", "generator",
1396"is_thrown", "auto_apply", "treasure", "player sold", /* 20 */ 1445"is_thrown", "auto_apply", "treasure", "player sold", /* 20 */
1420"activate_on_release", "is_water", "use_content_on_gen", NULL, "is_buildable", /* 110 */ 1469"activate_on_release", "is_water", "use_content_on_gen", NULL, "is_buildable", /* 110 */
1421NULL 1470NULL
1422}; 1471};
1423 1472
1424 1473
1425void save_double(char *buf,char *name,double v)
1426{
1427 char tbuf[200];
1428
1429 sprintf(tbuf,"%s %f\n",name,v);
1430 strcat(buf,tbuf);
1431}
1432
1433/* 1474/*
1434 * Initialises the array of variable-names. Needed before any 1475 * Initialises the array of variable-names. Needed before any
1435 * objects can be loaded. Called by init_library(). 1476 * objects can be loaded. Called by init_library().
1436 */ 1477 */
1437 1478
1438void init_vars() { 1479void init_vars() {
1439} 1480}
1440 1481
1441/*For get_ob_diff speed reason*/ 1482/*For get_ob_diff speed reason*/
1442typedef struct { 1483typedef struct {
1443 char* name; 1484 const char *name;
1444 int length; 1485 int length;
1445}genericname; 1486}genericname;
1446static genericname evtnames[13]= 1487static genericname evtnames[13]=
1447{ 1488{
1448 {"event_none ",11}, 1489 {"event_none ",11},
1491 {"event_throw_options ",20}, 1532 {"event_throw_options ",20},
1492 {"event_trigger_options ",22}, 1533 {"event_trigger_options ",22},
1493 {"event_close_options ",20}, 1534 {"event_close_options ",20},
1494 {"event_timer_options ",20} 1535 {"event_timer_options ",20}
1495}; 1536};
1537
1538/* This returns a string of the integer movement type */
1539static char* get_string_move_type(MoveType mt)
1540{
1541 static char retbuf[MAX_BUF], retbuf_all[MAX_BUF];
1542 int i, all_count=0, count;
1543
1544 strcpy(retbuf,"");
1545 strcpy(retbuf_all," all");
1546
1547 /* Quick check, and probably fairly common */
1548 if (mt == MOVE_ALL) return retbuf_all+1;
1549 if (mt == 0) {
1550 strcpy(retbuf,"0");
1551 return retbuf;
1552 }
1553
1554 /* We basically slide the bits down. Why look at MOVE_ALL?
1555 * because we may want to return a string like 'all -swim',
1556 * and if we just looked at mt, we couldn't get that.
1557 */
1558 for (i=MOVE_ALL, count=0; i!=0; i >>= 1, count++) {
1559 if (mt & (1<<count)) {
1560 strcat(retbuf, " ");
1561 strcat(retbuf, move_name[count]);
1562 } else {
1563 strcat(retbuf_all, " -");
1564 strcat(retbuf_all, move_name[count]);
1565 all_count++;
1566 }
1567 }
1568 /* Basically, if there is a single negation, return it, eg
1569 * 'all -swim'. But more than that, just return the
1570 * enumerated values. It doesn't make sense to return
1571 * 'all -walk -fly_low' - it is shorter to return 'fly_high swim'
1572 */
1573 if (all_count <=1) return retbuf_all+1;
1574 else return retbuf+1;
1575}
1576
1496 1577
1497/* 1578/*
1498 * Returns a pointer to a static string which contains all variables 1579 * Returns a pointer to a static string which contains all variables
1499 * which are different in the two given objects. op is the what object 1580 * which are different in the two given objects. op is the what object
1500 * the different values will be taken from. This function is 1581 * the different values will be taken from. This function is
1684 if(op->stats.maxgrace!=op2->stats.maxgrace) 1765 if(op->stats.maxgrace!=op2->stats.maxgrace)
1685 FAST_SAVE_LONG(fastbuf,"maxgrace ",op->stats.maxgrace,9); 1766 FAST_SAVE_LONG(fastbuf,"maxgrace ",op->stats.maxgrace,9);
1686 1767
1687 if(op->stats.exp!=op2->stats.exp) { 1768 if(op->stats.exp!=op2->stats.exp) {
1688#ifndef WIN32 1769#ifndef WIN32
1689 sprintf(buf2,"%lld\n", op->stats.exp); 1770 sprintf(buf2,"%lld", op->stats.exp);
1690#else 1771#else
1691 sprintf(buf2,"%I64d\n", op->stats.exp); 1772 sprintf(buf2,"%I64d", op->stats.exp);
1692#endif 1773#endif
1693 ADD_STRINGLINE_ENTRY(fastbuf,"exp ", buf2, 4); 1774 ADD_STRINGLINE_ENTRY(fastbuf,"exp ", buf2, 4);
1694 } 1775 }
1695 1776
1696 if(op->perm_exp!=op2->perm_exp) { 1777 if(op->perm_exp!=op2->perm_exp) {
1697#ifndef WIN32 1778#ifndef WIN32
1698 sprintf(buf2,"%lld\n", op->perm_exp); 1779 sprintf(buf2,"%lld", op->perm_exp);
1699#else 1780#else
1700 sprintf(buf2,"%I64d\n", op->perm_exp); 1781 sprintf(buf2,"%I64d", op->perm_exp);
1701#endif 1782#endif
1702 ADD_STRINGLINE_ENTRY(fastbuf,"perm_exp ", buf2, 9); 1783 ADD_STRINGLINE_ENTRY(fastbuf,"perm_exp ", buf2, 9);
1703 } 1784 }
1704 1785
1705 if(op->expmul!=op2->expmul) 1786 if(op->expmul!=op2->expmul)
1843 1924
1844 if (op->gen_sp_armour != op2->gen_sp_armour) { 1925 if (op->gen_sp_armour != op2->gen_sp_armour) {
1845 FAST_SAVE_LONG(fastbuf,"gen_sp_armour ",op->gen_sp_armour,14); 1926 FAST_SAVE_LONG(fastbuf,"gen_sp_armour ",op->gen_sp_armour,14);
1846 } 1927 }
1847 1928
1929 /* I've kept the old int move type saving code commented out.
1930 * In an ideal world, we'd know if we want to do a quick
1931 * save (say to a temp map, where we don't care about strings),
1932 * or a slower save/dm dump, where printing out strings is handy.
1933 */
1848 if (op->move_type != op2->move_type) { 1934 if (op->move_type != op2->move_type) {
1849 FAST_SAVE_LONG(fastbuf,"move_type ",op->move_type,10); 1935 /*FAST_SAVE_LONG(fastbuf,"move_type ",op->move_type,10)*/
1936 ADD_STRINGLINE_ENTRY(fastbuf,"move_type ",
1937 get_string_move_type(op->move_type),
1938 10);
1850 } 1939 }
1851
1852 if (op->move_block != op2->move_block) { 1940 if (op->move_block != op2->move_block) {
1853 FAST_SAVE_LONG(fastbuf,"move_block ",op->move_block,11); 1941 /*FAST_SAVE_LONG(fastbuf,"move_block ",op->move_block,11)*/
1942 ADD_STRINGLINE_ENTRY(fastbuf,"move_block ",
1943 get_string_move_type(op->move_block),
1944 11);
1854 } 1945 }
1855 1946 if (op->move_allow != op2->move_allow) {
1947 /*FAST_SAVE_LONG(fastbuf,"move_allow ",op->move_allow,11);*/
1948 ADD_STRINGLINE_ENTRY(fastbuf,"move_allow ",
1949 get_string_move_type(op->move_allow),
1950 11);
1951 }
1856 if (op->move_on != op2->move_on) { 1952 if (op->move_on != op2->move_on) {
1857 FAST_SAVE_LONG(fastbuf,"move_on ",op->move_on,8); 1953 /*FAST_SAVE_LONG(fastbuf,"move_on ",op->move_on,8);*/
1954 ADD_STRINGLINE_ENTRY(fastbuf,"move_on ",
1955 get_string_move_type(op->move_on),
1956 8);
1858 } 1957 }
1859
1860 if (op->move_off != op2->move_off) { 1958 if (op->move_off != op2->move_off) {
1861 FAST_SAVE_LONG(fastbuf,"move_off ",op->move_off,9); 1959 /*FAST_SAVE_LONG(fastbuf,"move_off ",op->move_off,9);*/
1960 ADD_STRINGLINE_ENTRY(fastbuf,"move_off ",
1961 get_string_move_type(op->move_off),
1962 9);
1862 } 1963 }
1863 if (op->move_slow != op2->move_slow) { 1964 if (op->move_slow != op2->move_slow) {
1864 FAST_SAVE_LONG(fastbuf,"move_slow ",op->move_slow,10); 1965 /*FAST_SAVE_LONG(fastbuf,"move_slow ",op->move_slow,10);*/
1966 ADD_STRINGLINE_ENTRY(fastbuf,"move_slow ",
1967 get_string_move_type(op->move_slow),
1968 10);
1865 } 1969 }
1866 1970
1867 if (op->move_slow_penalty != op2->move_slow_penalty) { 1971 if (op->move_slow_penalty != op2->move_slow_penalty) {
1868 FAST_SAVE_LONG(fastbuf,"move_slow_penalty ",op->move_slow_penalty,18); 1972 FAST_SAVE_LONG(fastbuf,"move_slow_penalty ",op->move_slow_penalty,18);
1869 } 1973 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines