--- deliantra/server/common/treasure.C 2006/08/28 14:05:24 1.3 +++ deliantra/server/common/treasure.C 2006/08/31 18:59:23 1.6 @@ -1,7 +1,7 @@ /* * static char *rcs_treasure_c = - * "$Id: treasure.C,v 1.3 2006/08/28 14:05:24 root Exp $"; + * "$Id: treasure.C,v 1.6 2006/08/31 18:59:23 root Exp $"; */ /* @@ -109,45 +109,45 @@ nroftreasures++; while(fgets(buf,MAX_BUF,fp)!=NULL) { - (*line)++; + (*line)++; - if(*buf=='#') - continue; - if((cp=strchr(buf,'\n'))!=NULL) - *cp='\0'; - cp=buf; - while(isspace(*cp)) /* Skip blanks */ - cp++; - - if(sscanf(cp,"arch %s",variable)) { - if((t->item=find_archetype(variable))==NULL) - LOG(llevError,"Treasure lacks archetype: %s\n",variable); - } else if (sscanf(cp, "list %s", variable)) - t->name = add_string(variable); - else if (sscanf(cp, "change_name %s", variable)) - t->change_arch.name = add_string(variable); - else if (sscanf(cp, "change_title %s", variable)) - t->change_arch.title = add_string(variable); - else if (sscanf(cp, "change_slaying %s", variable)) - t->change_arch.slaying = add_string(variable); - else if(sscanf(cp,"chance %d",&value)) - t->chance=(uint8) value; - else if(sscanf(cp,"nrof %d",&value)) - t->nrof=(uint16) value; - else if(sscanf(cp,"magic %d",&value)) - t->magic=(uint8) value; - else if(!strcmp(cp,"yes")) - t->next_yes=load_treasure(fp, line); - else if(!strcmp(cp,"no")) - t->next_no=load_treasure(fp, line); - else if(!strcmp(cp,"end")) - return t; - else if(!strcmp(cp,"more")) { - t->next=load_treasure(fp, line); - return t; - } else - LOG(llevError,"Unknown treasure-command: '%s', last entry %s, line %d\n", - cp,t->name?t->name:"null", *line); + if(*buf=='#') + continue; + if((cp=strchr(buf,'\n'))!=NULL) + *cp='\0'; + cp=buf; + while(isspace(*cp)) /* Skip blanks */ + cp++; + + if(sscanf(cp,"arch %s",variable)) { + if((t->item=find_archetype(variable))==NULL) + LOG(llevError,"Treasure lacks archetype: %s\n",variable); + } else if (sscanf(cp, "list %s", variable)) + t->name = add_string(variable); + else if (sscanf(cp, "change_name %s", variable)) + t->change_arch.name = add_string(variable); + else if (sscanf(cp, "change_title %s", variable)) + t->change_arch.title = add_string(variable); + else if (sscanf(cp, "change_slaying %s", variable)) + t->change_arch.slaying = add_string(variable); + else if(sscanf(cp,"chance %d",&value)) + t->chance=(uint8) value; + else if(sscanf(cp,"nrof %d",&value)) + t->nrof=(uint16) value; + else if(sscanf(cp,"magic %d",&value)) + t->magic=(uint8) value; + else if(!strcmp(cp,"yes")) + t->next_yes=load_treasure(fp, line); + else if(!strcmp(cp,"no")) + t->next_no=load_treasure(fp, line); + else if(!strcmp(cp,"end")) + return t; + else if(!strcmp(cp,"more")) { + t->next=load_treasure(fp, line); + return t; + } else + LOG(llevError,"Unknown treasure-command: '%s', last entry %s, line %d\n", + cp,t->name?t->name:"null", *line); } LOG(llevError,"treasure lacks 'end'.\n"); return t; @@ -160,13 +160,13 @@ static void check_treasurelist(const treasure *t, const treasurelist *tl) { if (t->item==NULL && t->name==NULL) - LOG(llevError,"Treasurelist %s has element with no name or archetype\n", tl->name); + LOG(llevError,"Treasurelist %s has element with no name or archetype\n", tl->name); if (t->chance>=100 && t->next_yes && (t->next || t->next_no)) - LOG(llevError,"Treasurelist %s has element that has 100%% generation, next_yes field as well as next or next_no\n", - tl->name); + LOG(llevError,"Treasurelist %s has element that has 100%% generation, next_yes field as well as next or next_no\n", + tl->name); /* find_treasurelist will print out its own error message */ - if (t->name && strcmp(t->name,"NONE")) - (void) find_treasurelist(t->name); + if (t->name && *t->name) + (void) find_treasurelist(t->name); if (t->next) check_treasurelist(t->next, tl); if (t->next_yes) check_treasurelist(t->next_yes,tl); if (t->next_no) check_treasurelist(t->next_no, tl); @@ -187,42 +187,42 @@ sprintf(filename,"%s/%s",settings.datadir,settings.treasures); if((fp=open_and_uncompress(filename,0,&comp))==NULL) { - LOG(llevError,"Can't open treasure file.\n"); - return; + LOG(llevError,"Can't open treasure file.\n"); + return; } while(fgets(buf,MAX_BUF,fp)!=NULL) { - line++; - if(*buf=='#') - continue; - - if(sscanf(buf,"treasureone %s\n",name) || sscanf(buf,"treasure %s\n",name)) { - treasurelist *tl=get_empty_treasurelist(); - tl->name=add_string(name); - if(previous==NULL) - first_treasurelist=tl; - else - previous->next=tl; - previous=tl; - tl->items=load_treasure(fp, &line); - - /* This is a one of the many items on the list should be generated. - * Add up the chance total, and check to make sure the yes & no - * fields of the treasures are not being used. - */ - if (!strncmp(buf,"treasureone",11)) { - for (t=tl->items; t!=NULL; t=t->next) { + line++; + if(*buf=='#') + continue; + + if(sscanf(buf,"treasureone %s\n",name) || sscanf(buf,"treasure %s\n",name)) { + treasurelist *tl=get_empty_treasurelist(); + tl->name=add_string(name); + if(previous==NULL) + first_treasurelist=tl; + else + previous->next=tl; + previous=tl; + tl->items=load_treasure(fp, &line); + + /* This is a one of the many items on the list should be generated. + * Add up the chance total, and check to make sure the yes & no + * fields of the treasures are not being used. + */ + if (!strncmp(buf,"treasureone",11)) { + for (t=tl->items; t!=NULL; t=t->next) { #ifdef TREASURE_DEBUG - if (t->next_yes || t->next_no) { - LOG(llevError,"Treasure %s is one item, but on treasure %s\n", - tl->name, t->item ? t->item->name : t->name); - LOG(llevError," the next_yes or next_no field is set\n"); - } + if (t->next_yes || t->next_no) { + LOG(llevError,"Treasure %s is one item, but on treasure %s\n", + tl->name, t->item ? t->item->name : t->name); + LOG(llevError," the next_yes or next_no field is set\n"); + } #endif - tl->total_chance += t->chance; - } - } - } else - LOG(llevError,"Treasure-list %s didn't understand: %s, line %d\n", filename, buf, line); + tl->total_chance += t->chance; + } + } + } else + LOG(llevError,"Treasure-list %s didn't understand: %s, line %d\n", filename, buf, line); } close_and_delete(fp, comp); @@ -233,7 +233,7 @@ * or archetype is set for each treasure element. */ for (previous=first_treasurelist; previous!=NULL; previous=previous->next) - check_treasurelist(previous->items, previous); + check_treasurelist(previous->items, previous); #endif } @@ -286,7 +286,7 @@ if (flags & GT_ENVIRONMENT && op->type != SPELL) { op->x = creator->x; op->y = creator->y; - SET_FLAG(op, FLAG_OBJ_ORIGINAL); + SET_FLAG(op, FLAG_OBJ_ORIGINAL); insert_ob_in_map (op, creator->map,op,INS_NO_MERGE | INS_NO_WALK_ON); } else { op = insert_ob_in_ob (op, creator); @@ -305,9 +305,9 @@ /* CMD: change_name xxxx */ if(t->change_arch.name) { - FREE_AND_COPY(op->name, t->change_arch.name); - /* not great, but better than something that is completely wrong */ - FREE_AND_COPY(op->name_pl, t->change_arch.name); + FREE_AND_COPY(op->name, t->change_arch.name); + /* not great, but better than something that is completely wrong */ + FREE_AND_COPY(op->name_pl, t->change_arch.name); } if(t->change_arch.title) @@ -332,8 +332,8 @@ if((int)t->chance >= 100 || (RANDOM()%100 + 1) < (int) t->chance) { if (t->name) { - if (strcmp(t->name,"NONE") && difficulty>=t->magic) - create_treasure(find_treasurelist(t->name), op, flag, difficulty, tries); + if (strcmp(t->name,"NONE") && difficulty>=t->magic) + create_treasure(find_treasurelist(t->name), op, flag, difficulty, tries); } else { if(t->item->clone.invisible != 0 || ! (flag & GT_INVISIBLE)) { @@ -355,36 +355,36 @@ } void create_one_treasure(treasurelist *tl, object *op, int flag, int difficulty, - int tries) + int tries) { int value = RANDOM() % tl->total_chance; treasure *t; if (tries++>100) { - LOG(llevDebug,"create_one_treasure: tries exceeded 100, returning without making treasure\n"); - return; + LOG(llevDebug,"create_one_treasure: tries exceeded 100, returning without making treasure\n"); + return; } for (t=tl->items; t!=NULL; t=t->next) { - value -= t->chance; - if (value<0) break; + value -= t->chance; + if (value<0) break; } if (!t || value>=0) { - LOG(llevError, "create_one_treasure: got null object or not able to find treasure\n"); + LOG(llevError, "create_one_treasure: got null object or not able to find treasure\n"); abort(); - return; + return; } if (t->name) { - if (!strcmp(t->name,"NONE")) return; - if (difficulty>=t->magic) - create_treasure(find_treasurelist(t->name), op, flag, difficulty, tries); - else if (t->nrof) - create_one_treasure(tl, op, flag, difficulty, tries); - return; + if (!strcmp(t->name,"NONE")) return; + if (difficulty>=t->magic) + create_treasure(find_treasurelist(t->name), op, flag, difficulty, tries); + else if (t->nrof) + create_one_treasure(tl, op, flag, difficulty, tries); + return; } if((t->item && t->item->clone.invisible != 0) || flag != GT_INVISIBLE) { - object *tmp=arch_to_object(t->item); - if (!tmp) return; + object *tmp=arch_to_object(t->item); + if (!tmp) return; if(t->nrof && tmp->nrof<=1) tmp->nrof = RANDOM()%((int) t->nrof) + 1; fix_generated_item (tmp, op, difficulty, t->magic, flag); @@ -401,15 +401,15 @@ * to do that. */ void create_treasure(treasurelist *t, object *op, int flag, int difficulty, - int tries) + int tries) { if (tries++>100) { - LOG(llevDebug,"createtreasure: tries exceeded 100, returning without making treasure\n"); - return; + LOG(llevDebug,"createtreasure: tries exceeded 100, returning without making treasure\n"); + return; } if (t->total_chance) - create_one_treasure(t, op, flag,difficulty, tries); + create_one_treasure(t, op, flag,difficulty, tries); else create_all_treasures(t->items, op, flag, difficulty, tries); } @@ -421,18 +421,18 @@ */ object *generate_treasure(treasurelist *t, int difficulty) { - object *ob = get_object(), *tmp; + object *ob = get_object(), *tmp; - create_treasure(t, ob, 0, difficulty, 0); + create_treasure(t, ob, 0, difficulty, 0); - /* Don't want to free the object we are about to return */ - tmp = ob->inv; - if (tmp!=NULL) remove_ob(tmp); - if (ob->inv) { - LOG(llevError,"In generate treasure, created multiple objects.\n"); - } - free_object(ob); - return tmp; + /* Don't want to free the object we are about to return */ + tmp = ob->inv; + if (tmp!=NULL) remove_ob(tmp); + if (ob->inv) { + LOG(llevError,"In generate treasure, created multiple objects.\n"); + } + free_object(ob); + return tmp; } /* @@ -614,110 +614,110 @@ int r=RANDOM()%(bonus>0?25:11); if(op->type==AMULET) { - if(!(RANDOM()%21)) - r=20+RANDOM()%2; - else { - if(RANDOM()&2) - r=10; - else - r=11+RANDOM()%9; - } + if(!(RANDOM()%21)) + r=20+RANDOM()%2; + else { + if(RANDOM()&2) + r=10; + else + r=11+RANDOM()%9; + } } switch(r) { - /* Redone by MSW 2000-11-26 to have much less code. Also, - * bonuses and penalties will stack and add to existing values. - * of the item. - */ - case 0: - case 1: - case 2: - case 3: - case 4: - case 5: - case 6: - set_attr_value(&op->stats, r, (signed char)(bonus + get_attr_value(&op->stats,r))); - break; - - case 7: - op->stats.dam+=bonus; - break; - - case 8: - op->stats.wc+=bonus; - break; - - case 9: - op->stats.food+=bonus; /* hunger/sustenance */ - break; - - case 10: - op->stats.ac+=bonus; - break; - - /* Item that gives protections/vulnerabilities */ - case 11: - case 12: - case 13: - case 14: - case 15: - case 16: - case 17: - case 18: - case 19: - { - int b=5+FABS(bonus),val,resist=RANDOM() % num_resist_table; - - /* Roughly generate a bonus between 100 and 35 (depending on the bonus) */ - val = 10 + RANDOM() % b + RANDOM() % b + RANDOM() % b + RANDOM() % b; - - /* Cursed items need to have higher negative values to equal out with - * positive values for how protections work out. Put another - * little random element in since that they don't always end up with - * even values. - */ - if (bonus<0) val = 2*-val - RANDOM() % b; - if (val>35) val=35; /* Upper limit */ - b=0; - while (op->resist[resist_table[resist]]!=0 && b<4) { - resist=RANDOM() % num_resist_table; - } - if (b==4) return; /* Not able to find a free resistance */ - op->resist[resist_table[resist]] = val; - /* We should probably do something more clever here to adjust value - * based on how good a resistance we gave. - */ - break; - } - case 20: - if(op->type==AMULET) { - SET_FLAG(op,FLAG_REFL_SPELL); - op->value*=11; - } else { - op->stats.hp=1; /* regenerate hit points */ - op->value*=4; - } - break; - - case 21: - if(op->type==AMULET) { - SET_FLAG(op,FLAG_REFL_MISSILE); - op->value*=9; - } else { - op->stats.sp=1; /* regenerate spell points */ - op->value*=3; - } - break; - - case 22: - op->stats.exp+=bonus; /* Speed! */ - op->value=(op->value*2)/3; - break; + /* Redone by MSW 2000-11-26 to have much less code. Also, + * bonuses and penalties will stack and add to existing values. + * of the item. + */ + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + set_attr_value(&op->stats, r, (signed char)(bonus + get_attr_value(&op->stats,r))); + break; + + case 7: + op->stats.dam+=bonus; + break; + + case 8: + op->stats.wc+=bonus; + break; + + case 9: + op->stats.food+=bonus; /* hunger/sustenance */ + break; + + case 10: + op->stats.ac+=bonus; + break; + + /* Item that gives protections/vulnerabilities */ + case 11: + case 12: + case 13: + case 14: + case 15: + case 16: + case 17: + case 18: + case 19: + { + int b=5+FABS(bonus),val,resist=RANDOM() % num_resist_table; + + /* Roughly generate a bonus between 100 and 35 (depending on the bonus) */ + val = 10 + RANDOM() % b + RANDOM() % b + RANDOM() % b + RANDOM() % b; + + /* Cursed items need to have higher negative values to equal out with + * positive values for how protections work out. Put another + * little random element in since that they don't always end up with + * even values. + */ + if (bonus<0) val = 2*-val - RANDOM() % b; + if (val>35) val=35; /* Upper limit */ + b=0; + while (op->resist[resist_table[resist]]!=0 && b<4) { + resist=RANDOM() % num_resist_table; + } + if (b==4) return; /* Not able to find a free resistance */ + op->resist[resist_table[resist]] = val; + /* We should probably do something more clever here to adjust value + * based on how good a resistance we gave. + */ + break; + } + case 20: + if(op->type==AMULET) { + SET_FLAG(op,FLAG_REFL_SPELL); + op->value*=11; + } else { + op->stats.hp=1; /* regenerate hit points */ + op->value*=4; + } + break; + + case 21: + if(op->type==AMULET) { + SET_FLAG(op,FLAG_REFL_MISSILE); + op->value*=9; + } else { + op->stats.sp=1; /* regenerate spell points */ + op->value*=3; + } + break; + + case 22: + op->stats.exp+=bonus; /* Speed! */ + op->value=(op->value*2)/3; + break; } if(bonus>0) - op->value*=2*bonus; + op->value*=2*bonus; else - op->value= -(op->value*2*bonus)/3; + op->value= -(op->value*2*bonus)/3; } /* @@ -1157,7 +1157,7 @@ artifactlist *al; for (al=first_artifactlist; al!=NULL; al=al->next) - if (al->type == type) return al; + if (al->type == type) return al; return NULL; } @@ -1175,12 +1175,12 @@ fprintf(logfile, "Artifact has type %d, total_chance=%d\n", al->type, al->total_chance); for (art=al->items; art!=NULL; art=art->next) { fprintf(logfile,"Artifact %-30s Difficulty %3d Chance %5d\n", - art->item->name, art->difficulty, art->chance); + art->item->name, art->difficulty, art->chance); if (art->allowed !=NULL) { - fprintf(logfile,"\tAllowed combinations:"); - for (next=art->allowed; next!=NULL; next=next->next) - fprintf(logfile, "%s,", next->name); - fprintf(logfile,"\n"); + fprintf(logfile,"\tAllowed combinations:"); + for (next=art->allowed; next!=NULL; next=next->next) + fprintf(logfile, "%s,", next->name); + fprintf(logfile,"\n"); } } } @@ -1200,39 +1200,39 @@ while (t != NULL) { if (t->name != NULL) - { - for (i = 0; i < depth; i++) - fprintf (logfile, " "); - fprintf (logfile, "{ (list: %s)\n", t->name); - tl = find_treasurelist (t->name); - dump_monster_treasure_rec (name, tl->items, depth + 2); - for (i = 0; i < depth; i++) - fprintf (logfile, " "); - fprintf (logfile, "} (end of list: %s)\n", t->name); - } + { + for (i = 0; i < depth; i++) + fprintf (logfile, " "); + fprintf (logfile, "{ (list: %s)\n", t->name); + tl = find_treasurelist (t->name); + dump_monster_treasure_rec (name, tl->items, depth + 2); + for (i = 0; i < depth; i++) + fprintf (logfile, " "); + fprintf (logfile, "} (end of list: %s)\n", t->name); + } else - { - for (i = 0; i < depth; i++) - fprintf (logfile, " "); - if (t->item->clone.type == FLESH) - fprintf (logfile, "%s's %s\n", name, t->item->clone.name); - else - fprintf (logfile, "%s\n", t->item->clone.name); - } + { + for (i = 0; i < depth; i++) + fprintf (logfile, " "); + if (t->item->clone.type == FLESH) + fprintf (logfile, "%s's %s\n", name, t->item->clone.name); + else + fprintf (logfile, "%s\n", t->item->clone.name); + } if (t->next_yes != NULL) - { - for (i = 0; i < depth; i++) - fprintf (logfile, " "); - fprintf (logfile, " (if yes)\n"); - dump_monster_treasure_rec (name, t->next_yes, depth + 1); - } + { + for (i = 0; i < depth; i++) + fprintf (logfile, " "); + fprintf (logfile, " (if yes)\n"); + dump_monster_treasure_rec (name, t->next_yes, depth + 1); + } if (t->next_no != NULL) - { - for (i = 0; i < depth; i++) - fprintf (logfile, " "); - fprintf (logfile, " (if no)\n"); - dump_monster_treasure_rec (name, t->next_no, depth + 1); - } + { + for (i = 0; i < depth; i++) + fprintf (logfile, " "); + fprintf (logfile, " (if no)\n"); + dump_monster_treasure_rec (name, t->next_no, depth + 1); + } t = t->next; } } @@ -1252,15 +1252,15 @@ for (at = first_archetype; at != NULL; at = at->next) if (! strcasecmp (at->clone.name, name) && at->clone.title == NULL) { - fprintf (logfile, "treasures for %s (arch: %s)\n", at->clone.name, - at->name); - if (at->clone.randomitems != NULL) - dump_monster_treasure_rec (at->clone.name, - at->clone.randomitems->items, 1); - else - fprintf (logfile, "(nothing)\n"); - fprintf (logfile, "\n"); - found++; + fprintf (logfile, "treasures for %s (arch: %s)\n", at->clone.name, + at->name); + if (at->clone.randomitems != NULL) + dump_monster_treasure_rec (at->clone.name, + at->clone.randomitems->items, 1); + else + fprintf (logfile, "(nothing)\n"); + fprintf (logfile, "\n"); + found++; } if (found == 0) fprintf (logfile, "No objects have the name %s!\n\n", name); @@ -1272,7 +1272,6 @@ void init_artifacts(void) { static int has_been_inited=0; - FILE *fp_; char filename[MAX_BUF], buf[HUGE_BUF], *cp, *next; artifact *art=NULL; linked_char *tmp; @@ -1283,78 +1282,73 @@ else has_been_inited = 1; sprintf(filename, "%s/artifacts", settings.datadir); - LOG(llevDebug, "Reading artifacts from %s...",filename); - if ((fp_ = open_and_uncompress(filename, 0, &comp)) == NULL) { - LOG(llevError, "Can't open %s.\n", filename); - return; - } + object_thawer thawer (filename); + + if (!thawer) + return; - object_thawer fp (fp_); - - while (fgets(buf, HUGE_BUF, fp)!=NULL) { - if (*buf=='#') continue; - if((cp=strchr(buf,'\n'))!=NULL) - *cp='\0'; - cp=buf; - while(*cp==' ') /* Skip blanks */ - cp++; + while (fgets(buf, HUGE_BUF, thawer)!=NULL) { + if (*buf=='#') continue; + if((cp=strchr(buf,'\n'))!=NULL) + *cp='\0'; + cp=buf; + while(*cp==' ') /* Skip blanks */ + cp++; if (*cp=='\0') continue; - if (!strncmp(cp, "Allowed", 7)) { - if (art==NULL) { - art=get_empty_artifact(); - nrofartifacts++; - } - cp = strchr(cp,' ') + 1; - if (!strcmp(cp,"all")) continue; - - do { - nrofallowedstr++; - if ((next=strchr(cp, ','))!=NULL) - *(next++) = '\0'; - tmp = (linked_char*) malloc(sizeof(linked_char)); - tmp->name = add_string(cp); - tmp->next = art->allowed; - art->allowed = tmp; - } while ((cp=next)!=NULL); - } - else if (sscanf(cp, "chance %d", &value)) - art->chance = (uint16) value; - else if (sscanf(cp, "difficulty %d", &value)) - art->difficulty = (uint8) value; - else if (!strncmp(cp, "Object",6)) { - art->item = (object *) calloc(1, sizeof(object)); - reset_object(art->item); - if (!load_object(fp, art->item,LO_LINEMODE,0)) - LOG(llevError,"Init_Artifacts: Could not load object.\n"); - art->item->name = add_string((strchr(cp, ' ')+1)); - al=find_artifactlist(art->item->type); - if (al==NULL) { - al = get_empty_artifactlist(); - al->type = art->item->type; - al->next = first_artifactlist; - first_artifactlist = al; - } - art->next = al->items; - al->items = art; - art = NULL; - } - else - LOG(llevError,"Unknown input in artifact file: %s\n", buf); - } + if (!strncmp(cp, "Allowed", 7)) { + if (art==NULL) { + art=get_empty_artifact(); + nrofartifacts++; + } + cp = strchr(cp,' ') + 1; + if (!strcmp(cp,"all")) continue; - close_and_delete(fp, comp); + do { + nrofallowedstr++; + if ((next=strchr(cp, ','))!=NULL) + *(next++) = '\0'; + tmp = (linked_char*) malloc(sizeof(linked_char)); + tmp->name = add_string(cp); + tmp->next = art->allowed; + art->allowed = tmp; + } while ((cp=next)!=NULL); + } + else if (sscanf(cp, "chance %d", &value)) + art->chance = (uint16) value; + else if (sscanf(cp, "difficulty %d", &value)) + art->difficulty = (uint8) value; + else if (!strncmp(cp, "Object",6)) { + art->item = (object *) calloc(1, sizeof(object)); + reset_object(art->item); + if (!load_object(thawer, art->item,LO_LINEMODE,0)) + LOG(llevError,"Init_Artifacts: Could not load object.\n"); + art->item->name = add_string((strchr(cp, ' ')+1)); + al=find_artifactlist(art->item->type); + if (al==NULL) { + al = get_empty_artifactlist(); + al->type = art->item->type; + al->next = first_artifactlist; + first_artifactlist = al; + } + art->next = al->items; + al->items = art; + art = NULL; + } + else + LOG(llevError,"Unknown input in artifact file: %s\n", buf); + } for (al=first_artifactlist; al!=NULL; al=al->next) { - for (art=al->items; art!=NULL; art=art->next) { - if (!art->chance) - LOG(llevError,"Warning: artifact with no chance: %s\n", art->item->name); - else - al->total_chance += art->chance; - } + for (art=al->items; art!=NULL; art=art->next) { + if (!art->chance) + LOG(llevError,"Warning: artifact with no chance: %s\n", art->item->name); + else + al->total_chance += art->chance; + } #if 0 - LOG(llevDebug,"Artifact list type %d has %d total chance\n", - al->type, al->total_chance); + LOG(llevDebug,"Artifact list type %d has %d total chance\n", + al->type, al->total_chance); #endif } @@ -1372,12 +1366,12 @@ if (change->face != blank_face) { #ifdef TREASURE_VERBOSE - LOG(llevDebug, "FACE: %d\n", change->face->number); + LOG(llevDebug, "FACE: %d\n", change->face->number); #endif - op->face = change->face; + op->face = change->face; } for (i = 0; i < NUM_STATS; i++) - change_attr_value(&(op->stats), i, get_attr_value(&(change->stats), i)); + change_attr_value(&(op->stats), i, get_attr_value(&(change->stats), i)); op->attacktype |= change->attacktype; op->path_attuned |= change->path_attuned; @@ -1389,8 +1383,8 @@ if (QUERY_FLAG(change,FLAG_CURSED)) SET_FLAG(op, FLAG_CURSED); if (QUERY_FLAG(change,FLAG_DAMNED)) SET_FLAG(op, FLAG_DAMNED); if ((QUERY_FLAG(change,FLAG_CURSED) || QUERY_FLAG(change,FLAG_DAMNED)) - && op->magic > 0) - set_abs_magic(op, -op->magic); + && op->magic > 0) + set_abs_magic(op, -op->magic); if (QUERY_FLAG(change,FLAG_LIFESAVE)) SET_FLAG(op,FLAG_LIFESAVE); if (QUERY_FLAG(change,FLAG_REFL_SPELL)) SET_FLAG(op,FLAG_REFL_SPELL); @@ -1402,10 +1396,10 @@ if (QUERY_FLAG(change,FLAG_MAKE_INVIS)) SET_FLAG(op,FLAG_MAKE_INVIS); if (QUERY_FLAG(change,FLAG_STAND_STILL)) { - CLEAR_FLAG(op,FLAG_ANIMATE); - /* so artifacts will join */ - if(!QUERY_FLAG(op,FLAG_ALIVE)) op->speed = 0.0; - update_ob_speed(op); + CLEAR_FLAG(op,FLAG_ANIMATE); + /* so artifacts will join */ + if(!QUERY_FLAG(op,FLAG_ALIVE)) op->speed = 0.0; + update_ob_speed(op); } if(change->nrof) op->nrof=RANDOM()%((int) change->nrof) + 1; op->stats.exp += change->stats.exp; /* Speed modifier */ @@ -1413,94 +1407,94 @@ op->stats.ac += change->stats.ac; if (change->other_arch) { - /* Basically, for horns & potions, the other_arch field is the spell - * to cast. So convert that to into a spell and put it into - * this object. - */ - if (op->type == HORN || op->type == POTION) { - object *tmp_obj; - /* Remove any spells this object currently has in it */ - while (op->inv) { - tmp_obj = op->inv; - remove_ob(tmp_obj); - free_object(tmp_obj); - } - tmp_obj = arch_to_object(change->other_arch); - insert_ob_in_ob(tmp_obj, op); - } - /* No harm setting this for potions/horns */ - op->other_arch = change->other_arch; + /* Basically, for horns & potions, the other_arch field is the spell + * to cast. So convert that to into a spell and put it into + * this object. + */ + if (op->type == HORN || op->type == POTION) { + object *tmp_obj; + /* Remove any spells this object currently has in it */ + while (op->inv) { + tmp_obj = op->inv; + remove_ob(tmp_obj); + free_object(tmp_obj); + } + tmp_obj = arch_to_object(change->other_arch); + insert_ob_in_ob(tmp_obj, op); + } + /* No harm setting this for potions/horns */ + op->other_arch = change->other_arch; } if (change->stats.hp < 0) - op->stats.hp = -change->stats.hp; + op->stats.hp = -change->stats.hp; else - op->stats.hp += change->stats.hp; + op->stats.hp += change->stats.hp; if (change->stats.maxhp < 0) - op->stats.maxhp = -change->stats.maxhp; + op->stats.maxhp = -change->stats.maxhp; else - op->stats.maxhp += change->stats.maxhp; + op->stats.maxhp += change->stats.maxhp; if (change->stats.sp < 0) - op->stats.sp = -change->stats.sp; + op->stats.sp = -change->stats.sp; else - op->stats.sp += change->stats.sp; + op->stats.sp += change->stats.sp; if (change->stats.maxsp < 0) - op->stats.maxsp = -change->stats.maxsp; + op->stats.maxsp = -change->stats.maxsp; else - op->stats.maxsp += change->stats.maxsp; + op->stats.maxsp += change->stats.maxsp; if (change->stats.food < 0) - op->stats.food = -(change->stats.food); + op->stats.food = -(change->stats.food); else - op->stats.food += change->stats.food; + op->stats.food += change->stats.food; if (change->level < 0) - op->level = -(change->level); + op->level = -(change->level); else - op->level += change->level; + op->level += change->level; if (change->gen_sp_armour < 0) - op->gen_sp_armour = -(change->gen_sp_armour); + op->gen_sp_armour = -(change->gen_sp_armour); else - op->gen_sp_armour = (op->gen_sp_armour * (change->gen_sp_armour)) / 100; + op->gen_sp_armour = (op->gen_sp_armour * (change->gen_sp_armour)) / 100; op->item_power = change->item_power; for (i=0; iresist[i]) { - op->resist[i] += change->resist[i]; - } + if (change->resist[i]) { + op->resist[i] += change->resist[i]; + } } if (change->stats.dam) { - if (change->stats.dam < 0) - op->stats.dam = (-change->stats.dam); - else if (op->stats.dam) { - tmp = (signed char) (((int)op->stats.dam * (int)change->stats.dam)/10); - if (tmp == op->stats.dam) { - if (change->stats.dam < 10) - op->stats.dam--; - else - op->stats.dam++; - } - else - op->stats.dam = tmp; - } + if (change->stats.dam < 0) + op->stats.dam = (-change->stats.dam); + else if (op->stats.dam) { + tmp = (signed char) (((int)op->stats.dam * (int)change->stats.dam)/10); + if (tmp == op->stats.dam) { + if (change->stats.dam < 10) + op->stats.dam--; + else + op->stats.dam++; + } + else + op->stats.dam = tmp; + } } if (change->weight) { - if (change->weight < 0) - op->weight = (-change->weight); - else - op->weight = (op->weight * (change->weight)) / 100; + if (change->weight < 0) + op->weight = (-change->weight); + else + op->weight = (op->weight * (change->weight)) / 100; } if (change->last_sp) { - if (change->last_sp < 0) - op->last_sp = (-change->last_sp); - else - op->last_sp = (signed char) (((int)op->last_sp * (int)change->last_sp) / (int) 100); + if (change->last_sp < 0) + op->last_sp = (-change->last_sp); + else + op->last_sp = (signed char) (((int)op->last_sp * (int)change->last_sp) / (int) 100); } if (change->gen_sp_armour) { - if (change->gen_sp_armour < 0) - op->gen_sp_armour = (-change->gen_sp_armour); - else - op->gen_sp_armour = (signed char) (((int)op->gen_sp_armour * ((int)change->gen_sp_armour)) + if (change->gen_sp_armour < 0) + op->gen_sp_armour = (-change->gen_sp_armour); + else + op->gen_sp_armour = (signed char) (((int)op->gen_sp_armour * ((int)change->gen_sp_armour)) / (int)100); } op->value *= change->value; @@ -1508,78 +1502,78 @@ if(change->material) op->material = change->material; if (change->materialname) { - if (op->materialname) - free_string(op->materialname); - op->materialname = add_refcount(change->materialname); + if (op->materialname) + free_string(op->materialname); + op->materialname = add_refcount(change->materialname); } if (change->slaying) { - if (op->slaying) - free_string(op->slaying); - op->slaying = add_refcount(change->slaying); + if (op->slaying) + free_string(op->slaying); + op->slaying = add_refcount(change->slaying); } if (change->race) { - if (op->race) - free_string(op->race); - op->race = add_refcount(change->race); + if (op->race) + free_string(op->race); + op->race = add_refcount(change->race); } if (change->msg) { - if (op->msg) - free_string(op->msg); - op->msg = add_refcount(change->msg); + if (op->msg) + free_string(op->msg); + op->msg = add_refcount(change->msg); } /* GROS: Added support for event_... in artifact file */ for(j=0;jhook)) { - if ((evt2)&&(evt2->hook)) { - free_string(evt2->hook); - free_string(evt2->plugin); - free_string(evt2->options); - evtp = NULL; - evtn = evt2->next; - if (evt2 == op->events) { - free(evt2); - op->events = evtn; - } - else { - evtp = op->events; - while (evtp->next != evt2) - evtp = evtp->next; - free(evt2); - evtp->next = evtn; - } - } - else if (evt2 == NULL) { - if (op->events == NULL) { - evt2 = (event *)malloc(sizeof(event)); - op->events = evt2; - } - else { - evtp = op->events; - while (evtp->next != NULL) - evtp = evtp->next; - evtp->next = (event *)malloc(sizeof(event)); - evt2 = evtp->next; - } - } - evt2->next = NULL; - evt2->hook = add_refcount(evt->hook); - evt2->plugin = add_refcount(evt->plugin); - evt2->type = j; - - if (evt->options) - evt2->options = add_refcount(evt->options); - else - evt2->options = NULL; - } + event *evt; + event *evt2; + event *evtn; + event *evtp; + + evt = find_event(change,j); + evt2= find_event(op,j); + + if ((evt) && (evt->hook)) { + if ((evt2)&&(evt2->hook)) { + free_string(evt2->hook); + free_string(evt2->plugin); + free_string(evt2->options); + evtp = NULL; + evtn = evt2->next; + if (evt2 == op->events) { + free(evt2); + op->events = evtn; + } + else { + evtp = op->events; + while (evtp->next != evt2) + evtp = evtp->next; + free(evt2); + evtp->next = evtn; + } + } + else if (evt2 == NULL) { + if (op->events == NULL) { + evt2 = (event *)malloc(sizeof(event)); + op->events = evt2; + } + else { + evtp = op->events; + while (evtp->next != NULL) + evtp = evtp->next; + evtp->next = (event *)malloc(sizeof(event)); + evt2 = evtp->next; + } + } + evt2->next = NULL; + evt2->hook = add_refcount(evt->hook); + evt2->plugin = add_refcount(evt->plugin); + evt2->type = j; + + if (evt->options) + evt2->options = add_refcount(evt->options); + else + evt2->options = NULL; + } } } @@ -1633,7 +1627,7 @@ LOG(llevDebug, "Generated artifact %s %s [%s]\n", op->name, op->title, describe_item(op, NULL)); if (!identified) - CLEAR_FLAG(op, FLAG_IDENTIFIED); + CLEAR_FLAG(op, FLAG_IDENTIFIED); } #endif return; @@ -1671,22 +1665,22 @@ roll -= art->chance; if (roll<0) break; } - + if (art == NULL || roll>=0) { #if 1 LOG(llevError, "Got null entry and non zero roll in generate_artifact, type %d\n", - op->type); + op->type); #endif return; } if (!strcmp(art->item->name,"NONE")) - return; + return; if (FABS(op->magic) < art->item->magic) continue; /* Not magic enough to be this item */ /* Map difficulty not high enough */ if (difficultydifficulty) - continue; + continue; if (!legal_artifact_combination(op, art)) { #ifdef TREASURE_VERBOSE @@ -1710,36 +1704,36 @@ int i; if(item->type==FLESH && donor) { - /* change the name */ - sprintf(tmpbuf,"%s's %s",donor->name,item->name); - FREE_AND_COPY(item->name, tmpbuf); - sprintf(tmpbuf,"%s's %s",donor->name,item->name_pl); - FREE_AND_COPY(item->name_pl, tmpbuf); - - /* weight is FLESH weight/100 * donor */ - if((item->weight = (signed long) (((double)item->weight/(double)100.0) * (double)donor->weight))==0) - item->weight=1; - - /* value is multiplied by level of donor */ - item->value *= isqrt(donor->level*2); - - /* food value */ - item->stats.food += (donor->stats.hp/100) + donor->stats.Con; - - /* flesh items inherit some abilities of donor, but not - * full effect. - */ - for (i=0; iresist[i] = donor->resist[i]/2; - - /* item inherits donor's level (important for quezals) */ - item->level = donor->level; - - /* if donor has some attacktypes, the flesh is poisonous */ - if(donor->attacktype&AT_POISON) - item->type=POISON; - if(donor->attacktype&AT_ACID) item->stats.hp = -1*item->stats.food; - SET_FLAG(item,FLAG_NO_STEAL); + /* change the name */ + sprintf(tmpbuf,"%s's %s",donor->name,item->name); + FREE_AND_COPY(item->name, tmpbuf); + sprintf(tmpbuf,"%s's %s",donor->name,item->name_pl); + FREE_AND_COPY(item->name_pl, tmpbuf); + + /* weight is FLESH weight/100 * donor */ + if((item->weight = (signed long) (((double)item->weight/(double)100.0) * (double)donor->weight))==0) + item->weight=1; + + /* value is multiplied by level of donor */ + item->value *= isqrt(donor->level*2); + + /* food value */ + item->stats.food += (donor->stats.hp/100) + donor->stats.Con; + + /* flesh items inherit some abilities of donor, but not + * full effect. + */ + for (i=0; iresist[i] = donor->resist[i]/2; + + /* item inherits donor's level (important for quezals) */ + item->level = donor->level; + + /* if donor has some attacktypes, the flesh is poisonous */ + if(donor->attacktype&AT_POISON) + item->type=POISON; + if(donor->attacktype&AT_ACID) item->stats.hp = -1*item->stats.food; + SET_FLAG(item,FLAG_NO_STEAL); } } @@ -1755,23 +1749,23 @@ || op->stats.Wis || op->stats.Int || op->stats.Cha ) return 1; for (i=0; iresist[i]) return 1; + if (op->resist[i]) return 1; return 0; } void free_treasurestruct(treasure *t) { - if (t->next) free_treasurestruct(t->next); - if (t->next_yes) free_treasurestruct(t->next_yes); - if (t->next_no) free_treasurestruct(t->next_no); - free(t); + if (t->next) free_treasurestruct(t->next); + if (t->next_yes) free_treasurestruct(t->next_yes); + if (t->next_no) free_treasurestruct(t->next_no); + free(t); } void free_charlinks(linked_char *lc) { - if (lc->next) free_charlinks(lc->next); - free(lc); + if (lc->next) free_charlinks(lc->next); + free(lc); } void free_artifact(artifact *at) @@ -1780,11 +1774,11 @@ if (at->next) free_artifact(at->next); if (at->allowed) free_charlinks(at->allowed); if (at->item) { - if (at->item->name) free_string(at->item->name); - if (at->item->name_pl) free_string(at->item->name_pl); - if (at->item->msg) free_string(at->item->msg); - if (at->item->title) free_string(at->item->title); - free(at->item); + if (at->item->name) free_string(at->item->name); + if (at->item->name_pl) free_string(at->item->name_pl); + if (at->item->msg) free_string(at->item->msg); + if (at->item->title) free_string(at->item->title); + free(at->item); } free(at); } @@ -1793,11 +1787,11 @@ { artifactlist *nextal; for (al=first_artifactlist; al!=NULL; al=nextal) { - nextal=al->next; - if (al->items) { - free_artifact(al->items); - } - free(al); + nextal=al->next; + if (al->items) { + free_artifact(al->items); + } + free(al); } } @@ -1806,10 +1800,10 @@ for (tl=first_treasurelist; tl!=NULL; tl=next) { - next=tl->next; - if (tl->name) free_string(tl->name); - if (tl->items) free_treasurestruct(tl->items); - free(tl); + next=tl->next; + if (tl->name) free_string(tl->name); + if (tl->items) free_treasurestruct(tl->items); + free(tl); } free_artifactlist(first_artifactlist); }