Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals

db2.c

Go to the documentation of this file.
00001 /***************************************************************************
00002  *  Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer,        *
00003  *  Michael Seifert, Hans Henrik Strfeldt, Tom Madsen, and Katja Nyboe.    *
00004  *                                                                         *
00005  *  Merc Diku Mud improvments copyright (C) 1992, 1993 by Michael          *
00006  *  Chastain, Michael Quan, and Mitchell Tse.                              *
00007  *                                                                         *
00008  *  In order to use any part of this Merc Diku Mud, you must comply with   *
00009  *  both the original Diku license in 'license.doc' as well the Merc       *
00010  *  license in 'license.txt'.  In particular, you may not remove either of *
00011  *  these copyright notices.                                               *
00012  *                                                                         *
00013  *  Much time and thought has gone into this software and you are          *
00014  *  benefitting.  We hope that you share your changes too.  What goes      *
00015  *  around, comes around.                                                  *
00016  **************************************************************************/
00017 
00018 /***************************************************************************
00019  *   ROM 2.4 is copyright 1993-1998 Russ Taylor                            *
00020  *   ROM has been brought to you by the ROM consortium                     *
00021  *       Russ Taylor (rtaylor@hypercube.org)                               *
00022  *       Gabrielle Taylor (gtaylor@hypercube.org)                          *
00023  *       Brian Moore (zump@rom.org)                                        *
00024  *   By using this code, you have agreed to follow the terms of the        *
00025  *   ROM license, in the file Rom24/doc/rom.license                        *
00026  **************************************************************************/
00027 
00028 #include <stdio.h>
00029 #include <string.h>
00030 #include <stdlib.h>
00031 #include <ctype.h>
00032 #include <time.h>
00033 #if defined(macintosh)
00034 #include <types.h>
00035 #else
00036 #include <sys/types.h>
00037 #include <sys/time.h>
00038 #endif
00039 
00040 #include "merc.h"
00041 #include "db.h"
00042 #include "tables.h"
00043 #include "lookup.h"
00044 
00045 extern unsigned long int o_count;
00046 extern unsigned long int m_count;
00047 extern unsigned long int reset_count;
00048 extern unsigned long int r_count;
00049 extern unsigned long int s_count;
00050 extern unsigned long int so_count;
00051 
00052 extern int flag_lookup
00053 args ((const char *name, const struct flag_type * flag_table));
00054 
00055 /* values for db2.c */
00056 struct social_type social_table[MAX_SOCIALS];
00057 int social_count;
00058 
00059 /* snarf a socials file */
00060 
00061 /* Re-done by Mike to allow for linked list instead
00062  * of that crappy table.
00063  */
00064 void load_socials (FILE * fp)
00065 {
00066     SOCIAL_LIST *social;
00067     for (;;)
00068     {
00069     social = new_social();
00070     so_count+=1;
00071     if (social == NULL)
00072     {
00073         bug("Social is null!", 1);
00074         return;
00075     }
00076     
00077         char *temp;
00078         /* clear social */
00079         social->char_no_arg = NULL;
00080         social->others_no_arg = NULL;
00081         social->char_found = NULL;
00082         social->others_found = NULL;
00083         social->vict_found = NULL;
00084         social->char_not_found = NULL;
00085         social->char_auto = NULL;
00086         social->others_auto = NULL;
00087 
00088         temp = fread_word (fp);
00089         if (!strcmp (temp, "#0"))
00090             return;                /* done */
00091 #if defined(social_debug)
00092         else
00093             fprintf (stderr, "%s\n\r", temp);
00094 #endif
00095 
00096         //strcpy (social.name, temp);
00097     
00098     
00099 //strcpy(social->name , temp);
00100     social->name = str_dup(&temp[0]);
00101         
00102     fread_to_eol (fp);
00103 
00104         temp = fread_string_eol (fp);
00105         if (!strcmp (temp, "$"))
00106             social->char_no_arg = NULL;
00107         else if (!strcmp (temp, "#"))
00108         {
00109             add_social(social);
00110         //social_table[social_count] = social;
00111             //social_count++;
00112             continue;
00113         }
00114         else
00115             social->char_no_arg = str_dup(&temp[0]);
00116 
00117         temp = fread_string_eol (fp);
00118         if (!strcmp (temp, "$"))
00119             social->others_no_arg = NULL;
00120         else if (!strcmp (temp, "#"))
00121         {
00122             add_social(social);
00123         //social_table[social_count] = social;
00124             //social_count++;
00125             continue;
00126         }
00127         else
00128             social->others_no_arg = str_dup(&temp[0]);
00129 
00130         temp = fread_string_eol (fp);
00131         if (!strcmp (temp, "$"))
00132             social->char_found = NULL;
00133         else if (!strcmp (temp, "#"))
00134         {
00135             add_social(social);
00136         //social_table[social_count] = social;
00137             //social_count++;
00138             continue;
00139         }
00140         else
00141             social->char_found = str_dup(&temp[0]);
00142 
00143         temp = fread_string_eol (fp);
00144         if (!strcmp (temp, "$"))
00145             social->others_found = NULL;
00146         else if (!strcmp (temp, "#"))
00147         {
00148             add_social(social);
00149         //social_table[social_count] = social;
00150             //social_count++;
00151             continue;
00152         }
00153         else
00154             social->others_found = str_dup(&temp[0]);
00155 
00156         temp = fread_string_eol (fp);
00157         if (!strcmp (temp, "$"))
00158             social->vict_found = NULL;
00159         else if (!strcmp (temp, "#"))
00160         {
00161         add_social(social);
00162             //social_table[social_count] = social;
00163             //social_count++;
00164             continue;
00165         }
00166         else
00167             social->vict_found = str_dup(&temp[0]);
00168 
00169         temp = fread_string_eol (fp);
00170         if (!strcmp (temp, "$"))
00171             social->char_not_found = NULL;
00172         else if (!strcmp (temp, "#"))
00173         {
00174         add_social(social);
00175             //social_table[social_count] = social;
00176             //social_count++;
00177             continue;
00178         }
00179         else
00180             social->char_not_found = str_dup(&temp[0]);
00181 
00182         temp = fread_string_eol (fp);
00183         if (!strcmp (temp, "$"))
00184             social->char_auto = NULL;
00185         else if (!strcmp (temp, "#"))
00186         {
00187             add_social(social);
00188         //social_table[social_count] = social;
00189             //social_count++;
00190             continue;
00191         }
00192         else
00193             social->char_auto = str_dup(&temp[0]);
00194 
00195         temp = fread_string_eol (fp);
00196         if (!strcmp (temp, "$"))
00197             social->others_auto = NULL;
00198         else if (!strcmp (temp, "#"))
00199         {
00200         add_social(social);
00201             //social_table[social_count] = social;
00202             //social_count++;
00203             continue;
00204         }
00205         else
00206             social->others_auto = str_dup(&temp[0]);
00207 
00208         add_social(social);
00209     //social_table[social_count] = social;
00210         //social_count++;
00211     }
00212     return;
00213 }
00214 
00215 
00216 
00217 
00218 
00219 
00220 /*
00221  * Snarf a mob section.  new style
00222  */
00223 void load_mobiles (FILE * fp)
00224 {
00225     MOB_INDEX_DATA *pMobIndex;
00226 
00227     if (!area_last)
00228     {                            /* OLC */
00229         bug ("Load_mobiles: no #AREA seen yet.", 0);
00230         exit (1);
00231     }
00232 
00233     for (;;)
00234     {
00235         int vnum;
00236         char letter;
00237         int iHash;
00238 
00239         letter = fread_letter (fp);
00240         if (letter != '#')
00241         {
00242             bug ("Load_mobiles: # not found.", 0);
00243             exit (1);
00244         }
00245 
00246         vnum = fread_number (fp);
00247         if (vnum == 0)
00248             break;
00249 
00250         fBootDb = FALSE;
00251         if (get_mob_index (vnum) != NULL)
00252         {
00253             bug ("Load_mobiles: vnum %d duplicated.", vnum);
00254             exit (1);
00255         }
00256         fBootDb = TRUE;
00257 
00258         pMobIndex = alloc_perm (sizeof (*pMobIndex));
00259         pMobIndex->vnum = vnum;
00260         pMobIndex->area = area_last;    /* OLC */
00261         pMobIndex->new_format = TRUE;
00262         newmobs++;
00263         pMobIndex->player_name = fread_string (fp);
00264     pMobIndex->short_descr = fread_string (fp);
00265         pMobIndex->long_descr = fread_string (fp);
00266         pMobIndex->description = fread_string (fp);
00267         pMobIndex->race = race_lookup (fread_string (fp));
00268 
00269         pMobIndex->long_descr[0] = UPPER (pMobIndex->long_descr[0]);
00270         pMobIndex->description[0] = UPPER (pMobIndex->description[0]);
00271 
00272         pMobIndex->act = fread_flag (fp) | ACT_IS_NPC
00273             | race_table[pMobIndex->race].act;
00274         pMobIndex->affected_by = fread_flag (fp)
00275             | race_table[pMobIndex->race].aff;
00276         pMobIndex->pShop = NULL;
00277         pMobIndex->alignment = fread_number (fp);
00278         pMobIndex->group = fread_number (fp);
00279 
00280         pMobIndex->level = fread_number (fp);
00281         pMobIndex->hitroll = fread_number (fp);
00282 
00283         /* read hit dice */
00284         pMobIndex->hit[DICE_NUMBER] = fread_number (fp);
00285         /* 'd'          */ fread_letter (fp);
00286         pMobIndex->hit[DICE_TYPE] = fread_number (fp);
00287         /* '+'          */ fread_letter (fp);
00288         pMobIndex->hit[DICE_BONUS] = fread_number (fp);
00289 
00290         /* read mana dice */
00291         pMobIndex->mana[DICE_NUMBER] = fread_number (fp);
00292         fread_letter (fp);
00293         pMobIndex->mana[DICE_TYPE] = fread_number (fp);
00294         fread_letter (fp);
00295         pMobIndex->mana[DICE_BONUS] = fread_number (fp);
00296 
00297         /* read damage dice */
00298         pMobIndex->damage[DICE_NUMBER] = fread_number (fp);
00299         fread_letter (fp);
00300         pMobIndex->damage[DICE_TYPE] = fread_number (fp);
00301         fread_letter (fp);
00302         pMobIndex->damage[DICE_BONUS] = fread_number (fp);
00303         pMobIndex->dam_type = attack_lookup (fread_word (fp));
00304 
00305         /* read armor class */
00306         pMobIndex->ac[AC_PIERCE] = fread_number (fp) * 10;
00307         pMobIndex->ac[AC_BASH] = fread_number (fp) * 10;
00308         pMobIndex->ac[AC_SLASH] = fread_number (fp) * 10;
00309         pMobIndex->ac[AC_EXOTIC] = fread_number (fp) * 10;
00310 
00311         /* read flags and add in data from the race table */
00312         pMobIndex->off_flags = fread_flag (fp)
00313             | race_table[pMobIndex->race].off;
00314         pMobIndex->imm_flags = fread_flag (fp)
00315             | race_table[pMobIndex->race].imm;
00316         pMobIndex->res_flags = fread_flag (fp)
00317             | race_table[pMobIndex->race].res;
00318         pMobIndex->vuln_flags = fread_flag (fp)
00319             | race_table[pMobIndex->race].vuln;
00320 
00321         /* vital statistics */
00322         pMobIndex->start_pos = position_lookup (fread_word (fp));
00323         pMobIndex->default_pos = position_lookup (fread_word (fp));
00324         pMobIndex->sex = sex_lookup (fread_word (fp));
00325 
00326         pMobIndex->wealth = fread_number (fp);
00327 
00328         pMobIndex->form = fread_flag (fp) | race_table[pMobIndex->race].form;
00329         pMobIndex->parts = fread_flag (fp)
00330             | race_table[pMobIndex->race].parts;
00331         /* size */
00332         CHECK_POS (pMobIndex->size, size_lookup (fread_word (fp)), "size");
00333 /*    pMobIndex->size            = size_lookup(fread_word(fp)); */
00334         pMobIndex->material = str_dup (fread_word (fp));
00335 
00336         for (;;)
00337         {
00338             letter = fread_letter (fp);
00339 
00340             if (letter == 'F')
00341             {
00342                 char *word;
00343                 long vector;
00344 
00345                 word = fread_word (fp);
00346                 vector = fread_flag (fp);
00347 
00348                 if (!str_prefix (word, "act"))
00349                     REMOVE_BIT (pMobIndex->act, vector);
00350                 else if (!str_prefix (word, "aff"))
00351                     REMOVE_BIT (pMobIndex->affected_by, vector);
00352                 else if (!str_prefix (word, "off"))
00353                     REMOVE_BIT (pMobIndex->off_flags, vector);
00354                 else if (!str_prefix (word, "imm"))
00355                     REMOVE_BIT (pMobIndex->imm_flags, vector);
00356                 else if (!str_prefix (word, "res"))
00357                     REMOVE_BIT (pMobIndex->res_flags, vector);
00358                 else if (!str_prefix (word, "vul"))
00359                     REMOVE_BIT (pMobIndex->vuln_flags, vector);
00360                 else if (!str_prefix (word, "for"))
00361                     REMOVE_BIT (pMobIndex->form, vector);
00362                 else if (!str_prefix (word, "par"))
00363                     REMOVE_BIT (pMobIndex->parts, vector);
00364                 else
00365                 {
00366                     bug ("Flag remove: flag not found.", 0);
00367                     exit (1);
00368                 }
00369             }
00370             else if (letter == 'M')
00371             {
00372                 MPROG_LIST *pMprog;
00373                 char *word;
00374                 int trigger = 0;
00375 
00376                 pMprog = alloc_perm (sizeof (*pMprog));
00377                 word = fread_word (fp);
00378                 if ((trigger = flag_lookup (word, mprog_flags)) == NO_FLAG)
00379                 {
00380                     bug ("MOBprogs: invalid trigger.", 0);
00381                     exit (1);
00382                 }
00383                 SET_BIT (pMobIndex->mprog_flags, trigger);
00384                 pMprog->trig_type = trigger;
00385                 pMprog->vnum = fread_number (fp);
00386                 pMprog->trig_phrase = fread_string (fp);
00387                 pMprog->next = pMobIndex->mprogs;
00388                 pMobIndex->mprogs = pMprog;
00389             }
00390             else
00391             {
00392                 ungetc (letter, fp);
00393                 break;
00394             }
00395         }
00396 
00397         iHash = vnum % MAX_KEY_HASH;
00398         pMobIndex->next = mob_index_hash[iHash];
00399         mob_index_hash[iHash] = pMobIndex;
00400         top_mob_index++;
00401         top_vnum_mob = top_vnum_mob < vnum ? vnum : top_vnum_mob;    /* OLC */
00402         assign_area_vnum (vnum);    /* OLC */
00403         kill_table[URANGE (0, pMobIndex->level, MAX_LEVEL - 1)].number++;
00404     m_count+=1;
00405     }
00406 
00407     return;
00408 }
00409 
00410 /*
00411  * Snarf an obj section. new style
00412  */
00413 void load_objects (FILE * fp)
00414 {
00415     OBJ_INDEX_DATA *pObjIndex;
00416 
00417     if (!area_last)
00418     {                            /* OLC */
00419         bug ("Load_objects: no #AREA seen yet.", 0);
00420         exit (1);
00421     }
00422 
00423     for (;;)
00424     {
00425         int vnum;
00426         char letter;
00427         int iHash;
00428 
00429         letter = fread_letter (fp);
00430         if (letter != '#')
00431     {
00432             bug ("Load_objects: # not found.", 0);
00433             exit (1);
00434         }
00435 
00436         vnum = fread_number (fp);
00437         if (vnum == 0)
00438             break;
00439 
00440         fBootDb = FALSE;
00441         if (get_obj_index (vnum) != NULL)
00442         {
00443             bug ("Load_objects: vnum %d duplicated.", vnum);
00444             exit (1);
00445         }
00446         fBootDb = TRUE;
00447 
00448         pObjIndex = alloc_perm (sizeof (*pObjIndex));
00449         pObjIndex->vnum = vnum;
00450         pObjIndex->area = area_last;    /* OLC */
00451         pObjIndex->new_format = TRUE;
00452         pObjIndex->reset_num = 0;
00453         newobjs++;
00454         pObjIndex->name = fread_string (fp);
00455         pObjIndex->short_descr = fread_string (fp);
00456         pObjIndex->description = fread_string (fp);
00457         pObjIndex->material = fread_string (fp);
00458 
00459         CHECK_POS (pObjIndex->item_type, item_lookup (fread_word (fp)),
00460                    "item_type");
00461         pObjIndex->extra_flags = fread_flag (fp);
00462         pObjIndex->wear_flags = fread_flag (fp);
00463         switch (pObjIndex->item_type)
00464         {
00465             case ITEM_WEAPON:
00466                 pObjIndex->value[0] = weapon_type (fread_word (fp));
00467                 pObjIndex->value[1] = fread_number (fp);
00468                 pObjIndex->value[2] = fread_number (fp);
00469                 pObjIndex->value[3] = attack_lookup (fread_word (fp));
00470                 pObjIndex->value[4] = fread_flag (fp);
00471                 break;
00472             case ITEM_CONTAINER:
00473                 pObjIndex->value[0] = fread_number (fp);
00474                 pObjIndex->value[1] = fread_flag (fp);
00475                 pObjIndex->value[2] = fread_number (fp);
00476                 pObjIndex->value[3] = fread_number (fp);
00477                 pObjIndex->value[4] = fread_number (fp);
00478                 break;
00479             case ITEM_DRINK_CON:
00480             case ITEM_FOUNTAIN:
00481                 pObjIndex->value[0] = fread_number (fp);
00482                 pObjIndex->value[1] = fread_number (fp);
00483                 CHECK_POS (pObjIndex->value[2], liq_lookup (fread_word (fp)),
00484                            "liq_lookup");
00485                 pObjIndex->value[3] = fread_number (fp);
00486                 pObjIndex->value[4] = fread_number (fp);
00487                 break;
00488             case ITEM_WAND:
00489             case ITEM_STAFF:
00490                 pObjIndex->value[0] = fread_number (fp);
00491                 pObjIndex->value[1] = fread_number (fp);
00492                 pObjIndex->value[2] = fread_number (fp);
00493                 pObjIndex->value[3] = skill_lookup (fread_word (fp));
00494                 pObjIndex->value[4] = fread_number (fp);
00495                 break;
00496             case ITEM_POTION:
00497             case ITEM_PILL:
00498             case ITEM_SCROLL:
00499                 pObjIndex->value[0] = fread_number (fp);
00500                 pObjIndex->value[1] = skill_lookup (fread_word (fp));
00501                 pObjIndex->value[2] = skill_lookup (fread_word (fp));
00502                 pObjIndex->value[3] = skill_lookup (fread_word (fp));
00503                 pObjIndex->value[4] = skill_lookup (fread_word (fp));
00504                 break;
00505             default:
00506                 pObjIndex->value[0] = fread_flag (fp);
00507                 pObjIndex->value[1] = fread_flag (fp);
00508                 pObjIndex->value[2] = fread_flag (fp);
00509                 pObjIndex->value[3] = fread_flag (fp);
00510                 pObjIndex->value[4] = fread_flag (fp);
00511                 break;
00512         }
00513         pObjIndex->level = fread_number (fp);
00514         pObjIndex->weight = fread_number (fp);
00515         pObjIndex->cost = fread_number (fp);
00516 
00517         /* condition */
00518         letter = fread_letter (fp);
00519         switch (letter)
00520         {
00521             case ('P'):
00522                 pObjIndex->condition = 100;
00523                 break;
00524             case ('G'):
00525                 pObjIndex->condition = 90;
00526                 break;
00527             case ('A'):
00528                 pObjIndex->condition = 75;
00529                 break;
00530             case ('W'):
00531                 pObjIndex->condition = 50;
00532                 break;
00533             case ('D'):
00534                 pObjIndex->condition = 25;
00535                 break;
00536             case ('B'):
00537                 pObjIndex->condition = 10;
00538                 break;
00539             case ('R'):
00540                 pObjIndex->condition = 0;
00541                 break;
00542             default:
00543                 pObjIndex->condition = 100;
00544                 break;
00545         }
00546 
00547         for (;;)
00548         {
00549             char letter;
00550 
00551             letter = fread_letter (fp);
00552 
00553             if (letter == 'A')
00554             {
00555                 AFFECT_DATA *paf;
00556 
00557                 paf = alloc_perm (sizeof (*paf));
00558                 paf->where = TO_OBJECT;
00559                 paf->type = -1;
00560                 paf->level = pObjIndex->level;
00561                 paf->duration = -1;
00562                 paf->location = fread_number (fp);
00563                 paf->modifier = fread_number (fp);
00564                 paf->bitvector = 0;
00565                 paf->next = pObjIndex->affected;
00566                 pObjIndex->affected = paf;
00567                 top_affect++;
00568             }
00569 
00570             else if (letter == 'F')
00571             {
00572                 AFFECT_DATA *paf;
00573 
00574                 paf = alloc_perm (sizeof (*paf));
00575                 letter = fread_letter (fp);
00576                 switch (letter)
00577                 {
00578                     case 'A':
00579                         paf->where = TO_AFFECTS;
00580                         break;
00581                     case 'I':
00582                         paf->where = TO_IMMUNE;
00583                         break;
00584                     case 'R':
00585                         paf->where = TO_RESIST;
00586                         break;
00587                     case 'V':
00588                         paf->where = TO_VULN;
00589                         break;
00590                     default:
00591                         bug ("Load_objects: Bad where on flag set.", 0);
00592                         exit (1);
00593                 }
00594                 paf->type = -1;
00595                 paf->level = pObjIndex->level;
00596                 paf->duration = -1;
00597                 paf->location = fread_number (fp);
00598                 paf->modifier = fread_number (fp);
00599                 paf->bitvector = fread_flag (fp);
00600                 paf->next = pObjIndex->affected;
00601                 pObjIndex->affected = paf;
00602                 top_affect++;
00603             }
00604 
00605             else if (letter == 'E')
00606             {
00607                 EXTRA_DESCR_DATA *ed;
00608 
00609                 ed = alloc_perm (sizeof (*ed));
00610                 ed->keyword = fread_string (fp);
00611                 ed->description = fread_string (fp);
00612                 ed->next = pObjIndex->extra_descr;
00613                 pObjIndex->extra_descr = ed;
00614                 top_ed++;
00615             }
00616 
00617             else
00618             {
00619                 ungetc (letter, fp);
00620                 break;
00621             }
00622         }
00623 
00624         iHash = vnum % MAX_KEY_HASH;
00625         pObjIndex->next = obj_index_hash[iHash];
00626         obj_index_hash[iHash] = pObjIndex;
00627         top_obj_index++;
00628         top_vnum_obj = top_vnum_obj < vnum ? vnum : top_vnum_obj;    /* OLC */
00629         assign_area_vnum (vnum);    /* OLC */
00630     o_count+=1;
00631     }
00632 
00633     return;
00634 }
00635 
00636 /*****************************************************************************
00637  Name:            convert_objects
00638  Purpose:    Converts all old format objects to new format
00639  Called by:    boot_db (db.c).
00640  Note:          Loops over all resets to find the level of the mob
00641                 loaded before the object to determine the level of
00642                 the object.
00643         It might be better to update the levels in load_resets().
00644         This function is not pretty.. Sorry about that :)
00645  Author:        Hugin
00646  ****************************************************************************/
00647 void convert_objects (void)
00648 {
00649     int vnum;
00650     AREA_DATA *pArea;
00651     RESET_DATA *pReset;
00652     MOB_INDEX_DATA *pMob = NULL;
00653     OBJ_INDEX_DATA *pObj;
00654     ROOM_INDEX_DATA *pRoom;
00655 
00656     if (newobjs == top_obj_index)
00657         return;                    /* all objects in new format */
00658 
00659     for (pArea = area_first; pArea; pArea = pArea->next)
00660     {
00661         for (vnum = pArea->min_vnum; vnum <= pArea->max_vnum; vnum++)
00662         {
00663             if (!(pRoom = get_room_index (vnum)))
00664                 continue;
00665 
00666             for (pReset = pRoom->reset_first; pReset; pReset = pReset->next)
00667             {
00668                 switch (pReset->command)
00669                 {
00670                     case 'M':
00671                         if (!(pMob = get_mob_index (pReset->arg1)))
00672                             bug ("Convert_objects: 'M': bad vnum %d.",
00673                                  pReset->arg1);
00674                         break;
00675 
00676                     case 'O':
00677                         if (!(pObj = get_obj_index (pReset->arg1)))
00678                         {
00679                             bug ("Convert_objects: 'O': bad vnum %d.",
00680                                  pReset->arg1);
00681                             break;
00682                         }
00683 
00684                         if (pObj->new_format)
00685                             continue;
00686 
00687                         if (!pMob)
00688                         {
00689                             bug ("Convert_objects: 'O': No mob reset yet.",
00690                                  0);
00691                             break;
00692                         }
00693 
00694                         pObj->level = pObj->level < 1 ? pMob->level - 2
00695                             : UMIN (pObj->level, pMob->level - 2);
00696                         break;
00697 
00698                     case 'P':
00699                         {
00700                             OBJ_INDEX_DATA *pObj, *pObjTo;
00701 
00702                             if (!(pObj = get_obj_index (pReset->arg1)))
00703                             {
00704                                 bug ("Convert_objects: 'P': bad vnum %d.",
00705                                      pReset->arg1);
00706                                 break;
00707                             }
00708 
00709                             if (pObj->new_format)
00710                                 continue;
00711 
00712                             if (!(pObjTo = get_obj_index (pReset->arg3)))
00713                             {
00714                                 bug ("Convert_objects: 'P': bad vnum %d.",
00715                                      pReset->arg3);
00716                                 break;
00717                             }
00718 
00719                             pObj->level = pObj->level < 1 ? pObjTo->level
00720                                 : UMIN (pObj->level, pObjTo->level);
00721                         }
00722                         break;
00723 
00724                     case 'G':
00725                     case 'E':
00726                         if (!(pObj = get_obj_index (pReset->arg1)))
00727                         {
00728                             bug ("Convert_objects: 'E' or 'G': bad vnum %d.",
00729                                  pReset->arg1);
00730                             break;
00731                         }
00732 
00733                         if (!pMob)
00734                         {
00735                             bug
00736                                 ("Convert_objects: 'E' or 'G': null mob for vnum %d.",
00737                                  pReset->arg1);
00738                             break;
00739                         }
00740 
00741                         if (pObj->new_format)
00742                             continue;
00743 
00744                         if (pMob->pShop)
00745                         {
00746                             switch (pObj->item_type)
00747                             {
00748                                 default:
00749                                     pObj->level = UMAX (0, pObj->level);
00750                                     break;
00751                                 case ITEM_PILL:
00752                                 case ITEM_POTION:
00753                                     pObj->level = UMAX (5, pObj->level);
00754                                     break;
00755                                 case ITEM_SCROLL:
00756                                 case ITEM_ARMOR:
00757                                 case ITEM_WEAPON:
00758                                     pObj->level = UMAX (10, pObj->level);
00759                                     break;
00760                                 case ITEM_WAND:
00761                                 case ITEM_TREASURE:
00762                                     pObj->level = UMAX (15, pObj->level);
00763                                     break;
00764                                 case ITEM_STAFF:
00765                                     pObj->level = UMAX (20, pObj->level);
00766                                     break;
00767                             }
00768                         }
00769                         else
00770                             pObj->level = pObj->level < 1 ? pMob->level
00771                                 : UMIN (pObj->level, pMob->level);
00772                         break;
00773                 }                /* switch ( pReset->command ) */
00774             }
00775         }
00776     }
00777 
00778     /* do the conversion: */
00779 
00780     for (pArea = area_first; pArea; pArea = pArea->next)
00781         for (vnum = pArea->min_vnum; vnum <= pArea->max_vnum; vnum++)
00782             if ((pObj = get_obj_index (vnum)))
00783                 if (!pObj->new_format)
00784                     convert_object (pObj);
00785 
00786     return;
00787 }
00788 
00789 
00790 
00791 /*****************************************************************************
00792  Name:        convert_object
00793  Purpose:    Converts an old_format obj to new_format
00794  Called by:    convert_objects (db2.c).
00795  Note:          Dug out of create_obj (db.c)
00796  Author:        Hugin
00797  ****************************************************************************/
00798 void convert_object (OBJ_INDEX_DATA * pObjIndex)
00799 {
00800     int level;
00801     int number, type;            /* for dice-conversion */
00802 
00803     if (!pObjIndex || pObjIndex->new_format)
00804         return;
00805 
00806     level = pObjIndex->level;
00807 
00808     pObjIndex->level = UMAX (0, pObjIndex->level);    /* just to be sure */
00809     pObjIndex->cost = 10 * level;
00810 
00811     switch (pObjIndex->item_type)
00812     {
00813         default:
00814             bug ("Obj_convert: vnum %d bad type.", pObjIndex->item_type);
00815             break;
00816 
00817         case ITEM_LIGHT:
00818         case ITEM_TREASURE:
00819         case ITEM_FURNITURE:
00820         case ITEM_TRASH:
00821         case ITEM_CONTAINER:
00822         case ITEM_DRINK_CON:
00823         case ITEM_KEY:
00824         case ITEM_FOOD:
00825         case ITEM_BOAT:
00826         case ITEM_CORPSE_NPC:
00827         case ITEM_CORPSE_PC:
00828         case ITEM_FOUNTAIN:
00829         case ITEM_MAP:
00830         case ITEM_CLOTHING:
00831         case ITEM_SCROLL:
00832             break;
00833 
00834         case ITEM_WAND:
00835         case ITEM_STAFF:
00836             pObjIndex->value[2] = pObjIndex->value[1];
00837             break;
00838 
00839         case ITEM_WEAPON:
00840 
00841             /*
00842              * The conversion below is based on the values generated
00843              * in one_hit() (fight.c).  Since I don't want a lvl 50 
00844              * weapon to do 15d3 damage, the min value will be below
00845              * the one in one_hit, and to make up for it, I've made 
00846              * the max value higher.
00847              * (I don't want 15d2 because this will hardly ever roll
00848              * 15 or 30, it will only roll damage close to 23.
00849              * I can't do 4d8+11, because one_hit there is no dice-
00850              * bounus value to set...)
00851              *
00852              * The conversion below gives:
00853 
00854              level:   dice      min      max      mean
00855              1:     1d8      1( 2)    8( 7)     5( 5)
00856              2:     2d5      2( 3)   10( 8)     6( 6)
00857              3:     2d5      2( 3)   10( 8)     6( 6)
00858              5:     2d6      2( 3)   12(10)     7( 7)
00859              10:     4d5      4( 5)   20(14)    12(10)
00860              20:     5d5      5( 7)   25(21)    15(14)
00861              30:     5d7      5(10)   35(29)    20(20)
00862              50:     5d11     5(15)   55(44)    30(30)
00863 
00864              */
00865 
00866             number = UMIN (level / 4 + 1, 5);
00867             type = (level + 7) / number;
00868 
00869             pObjIndex->value[1] = number;
00870             pObjIndex->value[2] = type;
00871             break;
00872 
00873         case ITEM_ARMOR:
00874             pObjIndex->value[0] = level / 5 + 3;
00875             pObjIndex->value[1] = pObjIndex->value[0];
00876             pObjIndex->value[2] = pObjIndex->value[0];
00877             break;
00878 
00879         case ITEM_POTION:
00880         case ITEM_PILL:
00881             break;
00882 
00883         case ITEM_MONEY:
00884             pObjIndex->value[0] = pObjIndex->cost;
00885             break;
00886     }
00887 
00888     pObjIndex->new_format = TRUE;
00889     ++newobjs;
00890 
00891     return;
00892 }
00893 
00894 
00895 
00896 
00897 /*****************************************************************************
00898  Name:        convert_mobile
00899  Purpose:    Converts an old_format mob into new_format
00900  Called by:    load_old_mob (db.c).
00901  Note:          Dug out of create_mobile (db.c)
00902  Author:        Hugin
00903  ****************************************************************************/
00904 void convert_mobile (MOB_INDEX_DATA * pMobIndex)
00905 {
00906     int i;
00907     int type, number, bonus;
00908     int level;
00909 
00910     if (!pMobIndex || pMobIndex->new_format)
00911         return;
00912 
00913     level = pMobIndex->level;
00914 
00915     pMobIndex->act |= ACT_WARRIOR;
00916 
00917     /*
00918      * Calculate hit dice.  Gives close to the hitpoints
00919      * of old format mobs created with create_mobile()  (db.c)
00920      * A high number of dice makes for less variance in mobiles
00921      * hitpoints.
00922      * (might be a good idea to reduce the max number of dice)
00923      *
00924      * The conversion below gives:
00925 
00926      level:     dice         min         max        diff       mean
00927      1:       1d2+6       7(  7)     8(   8)     1(   1)     8(   8)
00928      2:       1d3+15     16( 15)    18(  18)     2(   3)    17(  17)
00929      3:       1d6+24     25( 24)    30(  30)     5(   6)    27(  27)
00930      5:      1d17+42     43( 42)    59(  59)    16(  17)    51(  51)
00931      10:      3d22+96     99( 95)   162( 162)    63(  67)   131(    )
00932      15:     5d30+161    166(159)   311( 311)   145( 150)   239(    )
00933      30:    10d61+416    426(419)  1026(1026)   600( 607)   726(    )
00934      50:    10d169+920   930(923)  2610(2610)  1680(1688)  1770(    )
00935 
00936      The values in parenthesis give the values generated in create_mobile.
00937      Diff = max - min.  Mean is the arithmetic mean.
00938      (hmm.. must be some roundoff error in my calculations.. smurfette got
00939      1d6+23 hp at level 3 ? -- anyway.. the values above should be
00940      approximately right..)
00941      */
00942     type = level * level * 27 / 40;
00943     number = UMIN (type / 40 + 1, 10);    /* how do they get 11 ??? */
00944     type = UMAX (2, type / number);
00945     bonus = UMAX (0, level * (8 + level) * .9 - number * type);
00946 
00947     pMobIndex->hit[DICE_NUMBER] = number;
00948     pMobIndex->hit[DICE_TYPE] = type;
00949     pMobIndex->hit[DICE_BONUS] = bonus;
00950 
00951     pMobIndex->mana[DICE_NUMBER] = level;
00952     pMobIndex->mana[DICE_TYPE] = 10;
00953     pMobIndex->mana[DICE_BONUS] = 100;
00954 
00955     /*
00956      * Calculate dam dice.  Gives close to the damage
00957      * of old format mobs in damage()  (fight.c)
00958      */
00959     type = level * 7 / 4;
00960     number = UMIN (type / 8 + 1, 5);
00961     type = UMAX (2, type / number);
00962     bonus = UMAX (0, level * 9 / 4 - number * type);
00963 
00964     pMobIndex->damage[DICE_NUMBER] = number;
00965     pMobIndex->damage[DICE_TYPE] = type;
00966     pMobIndex->damage[DICE_BONUS] = bonus;
00967 
00968     switch (number_range (1, 3))
00969     {
00970         case (1):
00971             pMobIndex->dam_type = 3;
00972             break;                /* slash  */
00973         case (2):
00974             pMobIndex->dam_type = 7;
00975             break;                /* pound  */
00976         case (3):
00977             pMobIndex->dam_type = 11;
00978             break;                /* pierce */
00979     }
00980 
00981     for (i = 0; i < 3; i++)
00982         pMobIndex->ac[i] = interpolate (level, 100, -100);
00983     pMobIndex->ac[3] = interpolate (level, 100, 0);    /* exotic */
00984 
00985     pMobIndex->wealth /= 100;
00986     pMobIndex->size = SIZE_MEDIUM;
00987     pMobIndex->material = str_dup ("none");
00988 
00989     pMobIndex->new_format = TRUE;
00990     ++newmobs;
00991 
00992     return;
00993 }
00994 void load_classes( void )
00995 {
00996     FILE *fp;
00997     char buf[MAX_STRING_LENGTH];
00998     int class, i;
00999 
01000     /* Initialize Skill levels */
01001     {
01002     int sn, i;
01003     for ( sn = 0; sn < MAX_SKILL; sn++ )
01004     {
01005         twiddle();
01006         if ( skill_table[sn].name == NULL )
01007         break;
01008         
01009         for( i = 0; i < MAX_CLASS; i++ )
01010         {
01011         skill_table[sn].skill_level[i] = LEVEL_IMMORTAL;
01012         skill_table[sn].rating[i] = 0;
01013         }
01014     }
01015     }
01016 
01017     for (class = 0; class < MAX_CLASS; class++)
01018     {
01019         switch(class)
01020         {
01021         case (0): 
01022         sprintf(buf, "./class/mage.class");
01023          
01024         break; 
01025     case (1):
01026         sprintf( buf, "./class/cleric.class");
01027         
01028         break;
01029     case (2):
01030         sprintf( buf, "./class/thief.class");
01031         
01032         break;
01033     case (3):
01034         sprintf( buf, "./class/warrior.class");
01035         
01036         break;
01037     case (4):
01038         sprintf(buf, "./class/knight.class");
01039         
01040         break;
01041     case (5):
01042         sprintf(buf, "./class/citizen.class");
01043         
01044         break;
01045     case (6):
01046         sprintf(buf, "./class/Psionic.class");
01047         
01048         break;
01049     case (7):
01050         sprintf(buf, "./class/Priest.class");
01051         
01052         break;
01053 //case (7):
01054 //      sprintf(buf, "./class/Spellsword.class");
01055 //      send_to_all_copyover("Spellsword ");
01056 //      break;
01057 
01058         
01059     }
01060 
01061         if ( (fp = fopen( buf, "r" )) == NULL )
01062     {
01063         log_string( "Error opening class file." );
01064         exit(1);
01065     }
01066 
01067     printf("Opening class: %s\n\r", buf);
01068 
01069     for ( ;; )
01070     {
01071         char letter;
01072         char *word;
01073 
01074         letter = fread_letter( fp );
01075         if ( letter == '*' )
01076         {
01077         fread_to_eol( fp );
01078         continue;
01079         }
01080         if ( letter != '#' )
01081         {
01082         bug( "Load_classes: # not found.", 0 );
01083         break;
01084         }
01085         
01086         word = fread_word( fp );
01087 
01088         if ( !str_cmp( word, "CLASS" ) )
01089         {
01090         char *field;
01091 
01092             for ( ;; )
01093         {
01094             field = fread_word( fp );
01095             if ( !str_cmp( field, "Name" ) )
01096             class_table[class].name = fread_string( fp );
01097             else if ( !str_cmp( field, "WhoN" ) )
01098             {
01099             for( i = 0; i < 3; i++ )
01100                 class_table[class].who_name[i] = fread_letter( fp );
01101             }
01102             else if( !str_cmp( field, "Prime" ) )
01103             class_table[class].attr_prime = fread_number( fp );
01104             else if ( !str_cmp( field, "Weapon" ) )
01105             class_table[class].weapon = fread_number( fp );
01106             else if ( !str_cmp( field, "Guild1" ) )
01107             class_table[class].guild[0] = fread_number( fp );
01108             else if ( !str_cmp( field, "Guild2" ) )
01109             class_table[class].guild[1] = fread_number( fp );
01110             else if ( !str_cmp( field, "Skill" ) )
01111             class_table[class].skill_adept = fread_number( fp );
01112             else if ( !str_cmp( field, "Thac00" ) )
01113             class_table[class].thac0_00 = fread_number( fp );
01114             else if ( !str_cmp( field, "Thac32" ) )
01115             class_table[class].thac0_32 = fread_number( fp );
01116             else if ( !str_cmp( field, "HPMin" ) )
01117             class_table[class].hp_min = fread_number( fp );
01118             else if ( !str_cmp( field, "HPMax" ) )
01119             class_table[class].hp_max = fread_number( fp );
01120             else if ( !str_cmp( field, "FMana" ) )
01121             class_table[class].fMana = fread_number( fp );
01122             else if ( !str_cmp( field, "Pick" ) )
01123                 class_table[class].pick = fread_number( fp );
01124             else if ( !str_cmp( field, "Base" ) )
01125             class_table[class].base_group = fread_string( fp );
01126             else if ( !str_cmp( field, "Default" ) )
01127             class_table[class].default_group = fread_string( fp );
01128             else if ( !str_cmp( field, "End" ) )
01129             break;
01130         }
01131         }
01132         else if ( !str_cmp( word, "SKILLS" ) )
01133         {
01134         int sn;
01135         char *spell;
01136 
01137         for ( ;; )
01138         {
01139             spell = fread_string( fp );
01140 
01141             if ( !str_cmp( spell, "End" ) )
01142             {
01143     //      send_to_all_copyover("Done.\n\r");
01144                 break;
01145             }
01146     
01147 
01148             for ( sn = 0; sn < MAX_SKILL; sn++ )
01149             {
01150             if ( skill_table[sn].name == NULL )
01151                 break;
01152 
01153             if ( !str_cmp( spell, skill_table[sn].name ) )
01154             {
01155                 skill_table[sn].skill_level[class] = fread_number( fp );
01156                 skill_table[sn].rating[class] = fread_number( fp );
01157                 break;
01158             }
01159             }
01160         }
01161         }
01162         else if ( !str_cmp( word, "END" ) )
01163         {
01164     //  send_to_all_copyover("Done.\n\r");
01165         fclose( fp );
01166         break;
01167         }
01168     }
01169     }
01170 send_to_all_copyover("\bDone.\n\r");
01171 }
01172 
01173 void load_kingdom_data()
01174 {
01175     int king=0;
01176     int runner=1;
01177     char buf[MSL];
01178     FILE *fp;
01179     bool opened;
01180 
01181     for (king=0;king < MAX_KINGDOM;king++)
01182     {
01183         twiddle();
01184         if (kingdom_table[king].config == NULL)
01185         {
01186             opened = FALSE;
01187             continue;
01188         }
01189         sprintf(buf, "kingdom/%s", kingdom_table[king].config);
01190         if ((fp = fopen(buf, "r")) == NULL)
01191         {
01192             sprintf(buf, "Unable to open %s for reading\n\r", kingdom_table[king].config);
01193             bug (buf,0);
01194             opened = FALSE;
01195             continue;
01196         }
01197         /* Sanity checking */
01198         opened = TRUE;
01199         if (feof(fp))
01200             continue;
01201         if (!str_cmp(fread_word(fp), "Leader"))
01202             kingdom_data[king].leader = fread_string(fp);
01203         if (!str_cmp(fread_word(fp), "Members"))
01204             kingdom_data[king].member_count = fread_number(fp);
01205         for (runner=0;runner <=9;runner++)
01206         {
01207             sprintf(buf, "Rank%d", runner+1);
01208             if (!str_cmp(fread_word(fp), buf))
01209                 kingdom_data[king].rank[runner] = fread_string(fp);
01210             if (feof(fp))
01211                 continue;
01212         }
01213         if (!str_cmp(fread_word(fp), "Tithe"))
01214             kingdom_data[king].tithe = fread_number(fp);
01215         if (!str_cmp(fread_word(fp), "Taccount"))
01216             kingdom_data[king].tithe_account = (float)fread_number(fp);
01217     if (opened)
01218         fclose (fp);
01219     }
01220 //  fclose (fp);
01221 }
01222 
01223 void load_clan_data()
01224 {
01225     int clan=0;
01226     int runner=1;
01227     char buf[MSL];
01228     FILE *fp;
01229     bool opened;
01230 
01231     for (clan=0;clan < MAX_CLAN;clan++)
01232     {
01233         twiddle();
01234         if (clan_table[clan].config == NULL)
01235         {
01236             opened = FALSE;
01237             continue;
01238         }
01239         sprintf(buf, "clan/%s", clan_table[clan].config);
01240         if ((fp = fopen(buf, "r")) == NULL)
01241         {
01242             sprintf(buf, "Unable to open %s for reading\n\r", clan_table[clan].config);
01243             bug(buf,0);
01244             opened = FALSE;
01245             continue;
01246         }
01247         if (feof(fp))
01248             continue;
01249         opened = TRUE;
01250         if (!str_cmp(fread_word(fp), "Leader"))
01251             clan_data[clan].leader = fread_string(fp);
01252         if (!str_cmp(fread_word(fp), "Members"))
01253             clan_data[clan].member_count = fread_number(fp);
01254         for (runner=1;runner <=10;runner++)
01255         {
01256             sprintf(buf, "Rank%d", runner);
01257             if (!str_cmp(fread_word(fp), buf))
01258                 clan_data[clan].rank[runner] = fread_string(fp);
01259             if (feof(fp))
01260                 continue;
01261         }
01262         if (opened)
01263             fclose (fp);
01264     }
01265 //  fclose (fp);
01266 }
01267 
01268         
01269         
01270 
01271     

Generated on Thu Jan 13 21:48:10 2005 for Beyond the Shadows by  doxygen 1.4.0