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.1 by root, Fri Feb 3 07:11:36 2006 UTC vs.
Revision 1.1.1.2 by elmex, Wed Feb 22 18:01: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.1.1 2006/02/03 07:11:36 root Exp $"; 4 * "$Id: loader.l,v 1.1.1.2 2006/02/22 18:01:20 elmex 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);
1386/* This is a list of pointers that correspond to the FLAG_.. values. 1437/* 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 1438 * 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. 1439 * 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. 1440 * If an entry is NULL, that is a flag not to loaded/saved.
1390 */ 1441 */
1391static char *flag_names[NUM_FLAGS+1] = { 1442static const char *const flag_names[NUM_FLAGS+1] = {
1392"alive", "wiz", NULL, NULL, "was_wiz", "applied", "unpaid", 1443"alive", "wiz", NULL, NULL, "was_wiz", "applied", "unpaid",
1393"can_use_shield", "no_pick", NULL /* walk_on*/, NULL /* no_pass */, /* 10 */ 1444"can_use_shield", "no_pick", NULL /* walk_on*/, NULL /* no_pass */, /* 10 */
1394"is_animated", NULL /* slow_move */, 1445"is_animated", NULL /* slow_move */,
1395NULL /* flying */, "monster", "friendly", "generator", 1446NULL /* flying */, "monster", "friendly", "generator",
1396"is_thrown", "auto_apply", "treasure", "player sold", /* 20 */ 1447"is_thrown", "auto_apply", "treasure", "player sold", /* 20 */
1420"activate_on_release", "is_water", "use_content_on_gen", NULL, "is_buildable", /* 110 */ 1471"activate_on_release", "is_water", "use_content_on_gen", NULL, "is_buildable", /* 110 */
1421NULL 1472NULL
1422}; 1473};
1423 1474
1424 1475
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/* 1476/*
1434 * Initialises the array of variable-names. Needed before any 1477 * Initialises the array of variable-names. Needed before any
1435 * objects can be loaded. Called by init_library(). 1478 * objects can be loaded. Called by init_library().
1436 */ 1479 */
1437 1480
1438void init_vars() { 1481void init_vars() {
1439} 1482}
1440 1483
1441/*For get_ob_diff speed reason*/ 1484/*For get_ob_diff speed reason*/
1442typedef struct { 1485typedef struct {
1443 char* name; 1486 const char *name;
1444 int length; 1487 int length;
1445}genericname; 1488}genericname;
1446static genericname evtnames[13]= 1489static genericname evtnames[13]=
1447{ 1490{
1448 {"event_none ",11}, 1491 {"event_none ",11},
1491 {"event_throw_options ",20}, 1534 {"event_throw_options ",20},
1492 {"event_trigger_options ",22}, 1535 {"event_trigger_options ",22},
1493 {"event_close_options ",20}, 1536 {"event_close_options ",20},
1494 {"event_timer_options ",20} 1537 {"event_timer_options ",20}
1495}; 1538};
1539
1540/* This returns a string of the integer movement type */
1541static char* get_string_move_type(MoveType mt)
1542{
1543 static char retbuf[MAX_BUF], retbuf_all[MAX_BUF];
1544 int i, all_count=0, count;
1545
1546 strcpy(retbuf,"");
1547 strcpy(retbuf_all," all");
1548
1549 /* Quick check, and probably fairly common */
1550 if (mt == MOVE_ALL) return retbuf_all;
1551 if (mt == 0) {
1552 strcpy(retbuf,"0");
1553 return retbuf;
1554 }
1555
1556 /* We basically slide the bits down. Why look at MOVE_ALL?
1557 * because we may want to return a string like 'all -swim',
1558 * and if we just looked at mt, we couldn't get that.
1559 */
1560 for (i=MOVE_ALL, count=0; i!=0; i >>= 1, count++) {
1561 if (mt & (1<<count)) {
1562 strcat(retbuf, " ");
1563 strcat(retbuf, move_name[count]);
1564 } else {
1565 strcat(retbuf_all, " -");
1566 strcat(retbuf_all, move_name[count]);
1567 all_count++;
1568 }
1569 }
1570 /* Basically, if there is a single negation, return it, eg
1571 * 'all -swim'. But more than that, just return the
1572 * enumerated values. It doesn't make sense to return
1573 * 'all -walk -fly_low' - it is shorter to return 'fly_high swim'
1574 */
1575 if (all_count <=1) return retbuf_all;
1576 else return retbuf;
1577}
1578
1496 1579
1497/* 1580/*
1498 * Returns a pointer to a static string which contains all variables 1581 * 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 1582 * which are different in the two given objects. op is the what object
1500 * the different values will be taken from. This function is 1583 * the different values will be taken from. This function is
1843 1926
1844 if (op->gen_sp_armour != op2->gen_sp_armour) { 1927 if (op->gen_sp_armour != op2->gen_sp_armour) {
1845 FAST_SAVE_LONG(fastbuf,"gen_sp_armour ",op->gen_sp_armour,14); 1928 FAST_SAVE_LONG(fastbuf,"gen_sp_armour ",op->gen_sp_armour,14);
1846 } 1929 }
1847 1930
1931 /* I've kept the old int move type saving code commented out.
1932 * In an ideal world, we'd know if we want to do a quick
1933 * 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.
1935 */
1848 if (op->move_type != op2->move_type) { 1936 if (op->move_type != op2->move_type) {
1849 FAST_SAVE_LONG(fastbuf,"move_type ",op->move_type,10); 1937 /*FAST_SAVE_LONG(fastbuf,"move_type ",op->move_type,10)*/
1938 ADD_STRINGLINE_ENTRY(fastbuf,"move_type ",
1939 get_string_move_type(op->move_type),
1940 10);
1850 } 1941 }
1851
1852 if (op->move_block != op2->move_block) { 1942 if (op->move_block != op2->move_block) {
1853 FAST_SAVE_LONG(fastbuf,"move_block ",op->move_block,11); 1943 /*FAST_SAVE_LONG(fastbuf,"move_block ",op->move_block,11)*/
1944 ADD_STRINGLINE_ENTRY(fastbuf,"move_block ",
1945 get_string_move_type(op->move_block),
1946 11);
1854 } 1947 }
1855 1948 if (op->move_allow != op2->move_allow) {
1949 /*FAST_SAVE_LONG(fastbuf,"move_allow ",op->move_allow,11);*/
1950 ADD_STRINGLINE_ENTRY(fastbuf,"move_allow ",
1951 get_string_move_type(op->move_allow),
1952 11);
1953 }
1856 if (op->move_on != op2->move_on) { 1954 if (op->move_on != op2->move_on) {
1857 FAST_SAVE_LONG(fastbuf,"move_on ",op->move_on,8); 1955 /*FAST_SAVE_LONG(fastbuf,"move_on ",op->move_on,8);*/
1956 ADD_STRINGLINE_ENTRY(fastbuf,"move_on ",
1957 get_string_move_type(op->move_on),
1958 8);
1858 } 1959 }
1859
1860 if (op->move_off != op2->move_off) { 1960 if (op->move_off != op2->move_off) {
1861 FAST_SAVE_LONG(fastbuf,"move_off ",op->move_off,9); 1961 /*FAST_SAVE_LONG(fastbuf,"move_off ",op->move_off,9);*/
1962 ADD_STRINGLINE_ENTRY(fastbuf,"move_off ",
1963 get_string_move_type(op->move_off),
1964 9);
1862 } 1965 }
1863 if (op->move_slow != op2->move_slow) { 1966 if (op->move_slow != op2->move_slow) {
1864 FAST_SAVE_LONG(fastbuf,"move_slow ",op->move_slow,10); 1967 /*FAST_SAVE_LONG(fastbuf,"move_slow ",op->move_slow,10);*/
1968 ADD_STRINGLINE_ENTRY(fastbuf,"move_slow ",
1969 get_string_move_type(op->move_slow),
1970 10);
1865 } 1971 }
1866 1972
1867 if (op->move_slow_penalty != op2->move_slow_penalty) { 1973 if (op->move_slow_penalty != op2->move_slow_penalty) {
1868 FAST_SAVE_LONG(fastbuf,"move_slow_penalty ",op->move_slow_penalty,18); 1974 FAST_SAVE_LONG(fastbuf,"move_slow_penalty ",op->move_slow_penalty,18);
1869 } 1975 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines