--- deliantra/server/common/loader.l 2006/02/03 07:11:36 1.1 +++ deliantra/server/common/loader.l 2006/08/26 08:44:04 1.8 @@ -42,8 +42,12 @@ static char *yval(); static int lex_error; -static char msgbuf[HUGE_BUF]; -static char lorebuf[HUGE_BUF]; +static char msgbuf[65536]; +static char lorebuf[65536]; + +/* Maps the MOVE_* values to names */ +static const char *const move_name[] = {"walk", "fly_low", "fly_high", "swim", "boat", + NULL}; /* This table is only necessary to convert objects that existed before the * spell object conversion to the new object. It was not practical @@ -55,7 +59,7 @@ * NULL entries in this table are valid - to denote objects that should * not be updated for whatever reason. */ -char *spell_mapping[] = { +const char *spell_mapping[] = { "spell_magic_bullet", /* 0 */ "spell_small_fireball", /* 1 */ "spell_medium_fireball", /* 2 */ @@ -323,6 +327,35 @@ LOG(llevError,"set_body_info called with bogus params: %s\n", params); } +// return a suitable strign describign an objetc in enough detail to find it +// used only in check_loaded_object: TODO remove static, move it elsewhere and +// use it in more log messages. +static char *op_debug_info_ (object *op, char *info) +{ + char info2[256 * 3]; + char *p = info; + + p += snprintf (p, 256, "%d=\"%s%s%s\"", + op->count, + op->name ? op->name : "(anon)", + op->title ? " " : "", + op->title ? op->title : ""); + + if (op->env) + p += snprintf (p, 256, "(in %s)", op_debug_info_ (op->env, info2)); + + if (op->map) + p += snprintf (p, 256, "(on %s@%d+%d)", op->map->path, op->x, op->y); + + return info; +} + +static char *op_debug_info (object *op) +{ + static char info[256 * 3]; + + return op_debug_info_ (op, info); +} /* This function checks the object after it has been loaded (when we * get the 'end' in the input stream). This function can be used to @@ -361,11 +394,11 @@ */ if ((op->type == WEAPON || op->type==BOW) && arch_init) { if (!op->skill) { - LOG(llevError,"Weapon %s lacks a skill.\n", op->name); + LOG(llevError,"Weapon %s lacks a skill.\n", op_debug_info (op)); } else if ((!strcmp(op->skill,"one handed weapons") && op->body_info[1] != -1) || (!strcmp(op->skill,"two handed weapons") && op->body_info[1] != -2)) { LOG(llevError,"weapon %s arm usage does not match skill: %d, %s\n", - op->name, op->body_info[1], op->skill); + op_debug_info (op), op->body_info[1], op->skill); } } @@ -380,8 +413,7 @@ (op->type == AMULET ) || (op->type == GIRDLE) || (op->type == BRACERS ) || (op->type == CLOAK)) { if (op->last_heal) { - LOG(llevDebug,"Object %s still has last_heal set, not gen_sp_armour\n", - op->name?op->name:"NULL"); + LOG(llevDebug,"Object %s still has last_heal set, not gen_sp_armour\n", op_debug_info (op)); op->gen_sp_armour = op->last_heal; op->last_heal = 0; } @@ -390,8 +422,7 @@ /* Legacy objects from before item power was in the game */ if (!op->item_power && ip) { if (ip > 3) { - LOG(llevDebug,"Object %s had no item power, using %d\n", - op->name?op->name:"NULL", ip); + LOG(llevDebug,"Object %s had no item power, using %d\n", op_debug_info (op), ip); } op->item_power = ip; } @@ -403,7 +434,7 @@ */ if (ip > 2 *op->item_power && ip > (op->item_power + 3)) { LOG(llevDebug,"Object %s seems to have too low item power? %d > %d\n", - op->name?op->name:"NULL", ip, op->item_power); + op_debug_info (op), ip, op->item_power); } } @@ -436,7 +467,7 @@ if (QUERY_FLAG(op, FLAG_MONSTER)) { if (op->stats.hp > op->stats.maxhp) LOG(llevDebug,"Monster %s has hp set higher than maxhp (%d>%d)\n", - op->name, + op_debug_info (op), op->stats.hp, op->stats.maxhp); /* The archs just need to be updated for this */ @@ -537,6 +568,52 @@ set_ob_key_value(op, key, value, TRUE); } +static void set_move(MoveType *mt, char *params) { + char *str; + int i, negate; + + if (isdigit(*params)) { + *mt = atoi(params); + } else { + *mt=0; + for (str=strtok(params, " "); str; str=strtok(NULL, " ")) { + negate=0; + if (!strcasecmp(str, "all")) + *mt |= MOVE_ALL; + else { + if (*str=='-') { + negate = 1; + str++; + } + for (i=0; move_name[i] != NULL; i++) { + if (!strcasecmp(move_name[i], str)) { + if (negate) { + *mt &= ~(1<^endmsg{WS}$ { BEGIN( INITIAL ); - op->msg=add_string(msgbuf); /* Just print a warning so we can be reasonably safe * about not overflowing the buffer. */ - if (strlen(op->msg) > (HUGE_BUF/2)) - LOG(llevDebug, "\n\tWarning message length > %d (max allowed=%d): %d\n>%.80s<\n", - HUGE_BUF/2, HUGE_BUF, strlen(op->msg),op->msg); + if (strlen(msgbuf) >= HUGE_BUF) + { + LOG(llevDebug, "\n\tError message length >= %d: %d\n>%.80s<\n", + HUGE_BUF, strlen(op->msg),op->msg); + op->msg = add_string ("ERROR, please report: string too long, winged.\n"); + } + else + op->msg = add_string (msgbuf); } .* {strcat(msgbuf, yytext); strcat(msgbuf,"\n"); } @@ -614,6 +695,10 @@ if (*yv=='\0') LOG(llevError,"Name without val\n"); else FREE_AND_COPY(op->name_pl, yv); } +^attach{S} { char *yv=yval(); + if (*yv) + op->attach = add_string (yv); + } ^skill{S} FREE_AND_COPY(op->skill,yval()); ^custom_name{S} { char *yv=yval(); @@ -771,11 +856,12 @@ %{ /* These are the new values */ %} -^move_block{S} op->move_block = IVAL; -^move_type{S} op->move_type = IVAL; -^move_on{S} op->move_on = IVAL; -^move_off{S} op->move_off = IVAL; -^move_slow{S} op->move_slow = IVAL; +^move_block{S} set_move(&op->move_block, yval()); +^move_allow{S} set_move(&op->move_allow, yval()); +^move_type{S} set_move(&op->move_type, yval()); +^move_on{S} set_move(&op->move_on, yval()); +^move_off{S} set_move(&op->move_off, yval()); +^move_slow{S} set_move(&op->move_slow, yval()); ^move_slow_penalty{S} op->move_slow_penalty = FVAL; @@ -785,10 +871,8 @@ ^no_damage{S} SET_OR_CLEAR_FLAG(op, FLAG_NO_DAMAGE, IVAL); ^friendly{S} { if (IVAL) { SET_FLAG(op, FLAG_FRIENDLY); - if (op->type != PLAYER) { - LOG(llevDebug," Adding friendly object %s.\n",op->name); - add_friendly_object(op); - } + if (op->type != PLAYER) + add_friendly_object (op); } else CLEAR_FLAG(op, FLAG_FRIENDLY); } @@ -906,7 +990,7 @@ /* Old style resistances */ ^immune{S} set_protection(op, IVAL, RESIST_IMMUNE); ^protected{S} set_protection(op, IVAL, RESIST_PROT); -^vulnerable{S} set_protection(op, IVAL, RESIST_VULN); +^vulnerable{S} set_protection(op, IVAL, (uint16) RESIST_VULN); /* old values - keep them around for now, but they should be removed at some point */ ^has_ready_rod{S} SET_OR_CLEAR_FLAG(op, FLAG_READY_RANGE, IVAL); @@ -955,7 +1039,7 @@ ^can_dam_armour{S} { } ^weapontype{S} op->weapontype = IVAL; ^tooltype{S} op->tooltype = IVAL; -^casting_time{S} op->casting_time = FVAL; +^casting_time{S} op->casting_time = (sint16) FVAL; ^elevation{S} op->elevation = IVAL; ^smoothlevel{S} op->smoothlevel = IVAL; ^client_type{S} op->client_type = IVAL; @@ -1388,7 +1472,7 @@ * the 15'th element of this array should match that name. * If an entry is NULL, that is a flag not to loaded/saved. */ -static char *flag_names[NUM_FLAGS+1] = { +static const char *const flag_names[NUM_FLAGS+1] = { "alive", "wiz", NULL, NULL, "was_wiz", "applied", "unpaid", "can_use_shield", "no_pick", NULL /* walk_on*/, NULL /* no_pass */, /* 10 */ "is_animated", NULL /* slow_move */, @@ -1422,14 +1506,6 @@ }; -void save_double(char *buf,char *name,double v) -{ - char tbuf[200]; - - sprintf(tbuf,"%s %f\n",name,v); - strcat(buf,tbuf); -} - /* * Initialises the array of variable-names. Needed before any * objects can be loaded. Called by init_library(). @@ -1440,7 +1516,7 @@ /*For get_ob_diff speed reason*/ typedef struct { - char* name; + const char *name; int length; }genericname; static genericname evtnames[13]= @@ -1494,6 +1570,46 @@ {"event_timer_options ",20} }; +/* This returns a string of the integer movement type */ +static char* get_string_move_type(MoveType mt) +{ + static char retbuf[MAX_BUF], retbuf_all[MAX_BUF]; + int i, all_count=0, count; + + strcpy(retbuf,""); + strcpy(retbuf_all," all"); + + /* Quick check, and probably fairly common */ + if (mt == MOVE_ALL) return retbuf_all+1; + if (mt == 0) { + strcpy(retbuf,"0"); + return retbuf; + } + + /* We basically slide the bits down. Why look at MOVE_ALL? + * because we may want to return a string like 'all -swim', + * and if we just looked at mt, we couldn't get that. + */ + for (i=MOVE_ALL, count=0; i!=0; i >>= 1, count++) { + if (mt & (1<stats.exp!=op2->stats.exp) { #ifndef WIN32 - sprintf(buf2,"%lld\n", op->stats.exp); + sprintf(buf2,"%lld", op->stats.exp); #else - sprintf(buf2,"%I64d\n", op->stats.exp); + sprintf(buf2,"%I64d", op->stats.exp); #endif ADD_STRINGLINE_ENTRY(fastbuf,"exp ", buf2, 4); } if(op->perm_exp!=op2->perm_exp) { #ifndef WIN32 - sprintf(buf2,"%lld\n", op->perm_exp); + sprintf(buf2,"%lld", op->perm_exp); #else - sprintf(buf2,"%I64d\n", op->perm_exp); + sprintf(buf2,"%I64d", op->perm_exp); #endif ADD_STRINGLINE_ENTRY(fastbuf,"perm_exp ", buf2, 9); } @@ -1845,27 +1955,50 @@ FAST_SAVE_LONG(fastbuf,"gen_sp_armour ",op->gen_sp_armour,14); } + /* I've kept the old int move type saving code commented out. + * In an ideal world, we'd know if we want to do a quick + * save (say to a temp map, where we don't care about strings), + * or a slower save/dm dump, where printing out strings is handy. + */ if (op->move_type != op2->move_type) { - FAST_SAVE_LONG(fastbuf,"move_type ",op->move_type,10); + /*FAST_SAVE_LONG(fastbuf,"move_type ",op->move_type,10)*/ + ADD_STRINGLINE_ENTRY(fastbuf,"move_type ", + get_string_move_type(op->move_type), + 10); } - if (op->move_block != op2->move_block) { - FAST_SAVE_LONG(fastbuf,"move_block ",op->move_block,11); + /*FAST_SAVE_LONG(fastbuf,"move_block ",op->move_block,11)*/ + ADD_STRINGLINE_ENTRY(fastbuf,"move_block ", + get_string_move_type(op->move_block), + 11); + } + if (op->move_allow != op2->move_allow) { + /*FAST_SAVE_LONG(fastbuf,"move_allow ",op->move_allow,11);*/ + ADD_STRINGLINE_ENTRY(fastbuf,"move_allow ", + get_string_move_type(op->move_allow), + 11); } - if (op->move_on != op2->move_on) { - FAST_SAVE_LONG(fastbuf,"move_on ",op->move_on,8); + /*FAST_SAVE_LONG(fastbuf,"move_on ",op->move_on,8);*/ + ADD_STRINGLINE_ENTRY(fastbuf,"move_on ", + get_string_move_type(op->move_on), + 8); } - if (op->move_off != op2->move_off) { - FAST_SAVE_LONG(fastbuf,"move_off ",op->move_off,9); + /*FAST_SAVE_LONG(fastbuf,"move_off ",op->move_off,9);*/ + ADD_STRINGLINE_ENTRY(fastbuf,"move_off ", + get_string_move_type(op->move_off), + 9); } if (op->move_slow != op2->move_slow) { - FAST_SAVE_LONG(fastbuf,"move_slow ",op->move_slow,10); + /*FAST_SAVE_LONG(fastbuf,"move_slow ",op->move_slow,10);*/ + ADD_STRINGLINE_ENTRY(fastbuf,"move_slow ", + get_string_move_type(op->move_slow), + 10); } if (op->move_slow_penalty != op2->move_slow_penalty) { - FAST_SAVE_LONG(fastbuf,"move_slow_penalty ",op->move_slow_penalty,18); + FAST_SAVE_LONG(fastbuf,"move_slow_penalty ",(long) op->move_slow_penalty,18); } if (!COMPARE_FLAGS(op,op2)) {