home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 199.lha / DmfSrc_v2.5 / charedit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-12-27  |  26.5 KB  |  897 lines

  1. /* Charedit.c - Phase II of the Dungeon Master's familiar project
  2.  
  3.    Character Editing Module of Dungeon Master's Familiar
  4.  
  5.    James Gary
  6.    2-25-88
  7.  
  8.    3-4-88  Fixed for use with combat module JeG
  9.    3-11-88 Added Arps File Requestor JeG
  10.    3-12-88 Added Open/Close gadgets (duh!) JeG
  11.    3-14-88 Added AutoSelection of String Gadgets JeG
  12.    7-1-88  Added Saving Throws
  13.    7-1-88  Hit Dice now changes level gadget
  14.    7-10-88 Fixed memory leak by calling MxCloseWindow()
  15.    7-13-88 Added extra file list gadget for pasting from
  16.            external files
  17. */
  18.  
  19. /* INCLUDES ********************************************************** */
  20.  
  21. #include <stdio.h>
  22. #include <exec/types.h>
  23. #include <exec/io.h>
  24. #include <exec/memory.h>
  25. #include <libraries/dos.h>
  26. #include <intuition/intuition.h>
  27. #include "mxgadget.h"
  28. #include "charedit.h"
  29. #include "character.h"
  30. #include <libraries/arpbase.h>    /* Standard ARP header file */
  31. #include <proto/arpfunctions.h>    /* Predeclared functions */
  32. #include <libraries/itools1l.h>
  33.  
  34. int ClericSave[7][5] = {
  35.      {10,13,14,16,15},
  36.      { 9,12,13,15,14},
  37.      { 7,10,11,13,12},
  38.      { 6, 9,10,12,11},
  39.      { 5, 8, 9,11,10},
  40.      { 4, 7, 8,10, 9},
  41.      { 2, 5, 6, 8, 7}};
  42.  
  43. int FighterSave[10][5] = {
  44.      {16,17,18,20,19},
  45.      {14,15,16,17,17},
  46.      {13,14,15,16,16},
  47.      {11,12,13,13,14},
  48.      {10,11,12,12,13},
  49.      { 8, 9,10, 9,11},
  50.      { 7, 8, 9, 8,10},
  51.      { 5, 6, 7, 5, 8},
  52.      { 4, 5, 6, 4, 7},
  53.      { 3, 4, 5, 4, 6}};
  54.  
  55. MagicSave[5][5] = {
  56.      {14,13,11,15,12},
  57.      {13,11, 9,13,10},
  58.      {11, 9, 7,11, 8},
  59.      {10, 7, 5, 9, 6},
  60.      { 8, 5, 3, 7, 4}};
  61.  
  62. ThiefSave[6][5] = {
  63.      {13,12,14,16,15},
  64.      {12,11,12,15,13},
  65.      {11,10,10,14,11},
  66.      {10, 9, 8,13, 9},
  67.      { 9, 8, 8,13, 9},
  68.      { 8, 7, 4,11, 5}};
  69.  
  70. struct CharListItem {   /* structure for list display */
  71.      struct CharListItem *link;
  72.      struct Character *character;
  73.      short index;
  74.      } CharList[MAXCHARS];
  75. struct Character PatchChars[MAXCHARS]; /* Holds extra file data */
  76. struct Character *PasteChar; /* Selected extra character for pasting */
  77.  
  78. static USHORT quit_flag; /*For PW event handler*/
  79. static struct Window *wG; /*Main Combat window */
  80. struct Character characters[MAXCHARS]; /*Character array*/
  81. USHORT CurChar = 0; /*Holds postition in characters[]*/
  82.  
  83. /*Arp file requestor stuff*/
  84.  
  85. #define MAXPATH        ( (FCHARS * 10) + DSIZE + 1)    /* Size of a pathname */
  86.  
  87. BYTE Filename[FCHARS + 1];
  88. BYTE Directory[MAXPATH];
  89.  
  90. struct FileRequester FR = {
  91.     "Select a character file",    /* Hailing text */
  92.     Filename,            /* filename array */
  93.     Directory,            /* directory array */
  94.     NULL,        /* Window, NULL == workbench */
  95.     NULL,        /* Flags, not used in this release */
  96.     NULL,        /* Function pointers, not used in this release */
  97.     NULL,        /*  "" */
  98. };
  99.  
  100. /*Read a new character file from main combat window using ARP File req.*/
  101. ReadCharFile()
  102. {
  103.     FILE *charfile;
  104.     char *Selection;
  105.  
  106.     if ( Selection = FileRequest(&FR))
  107.     if (*Selection) {
  108.             if ((charfile = fopen(Filename,"r")) != NULL)
  109.                  fread((char *)characters,sizeof(struct Character),MAXCHARS,charfile);
  110.             else {
  111.                printf("File not found\n");
  112.                InitChars();
  113.             }
  114.        }
  115.     fclose(charfile);
  116.     PrintChars();
  117.     return(0);
  118. }
  119.  
  120. /*Write characters to file from main combat window using ARP File req.*/
  121. WriteCharFile()
  122. {
  123.     FILE *charfile;
  124.     char *Selection;
  125.  
  126.     if ( Selection = FileRequest(&FR))
  127.         if (*Selection) {
  128.             if ((charfile = fopen(Filename,"w")) != NULL)
  129.                 fwrite((char *)characters,sizeof(struct Character),MAXCHARS,charfile);
  130.             else
  131.                 printf("Panic! Could not open output file\n");
  132.         }
  133.     fclose(charfile);
  134.     return(0);
  135. }
  136.  
  137. /*Read character file from edit window using ARP file req.
  138.   and activate name gadget of current character for editing*/
  139. ReadEditFile()
  140. {
  141.     FILE *charfile;
  142.     char *Selection;
  143.  
  144.     if ( Selection = FileRequest(&FR))
  145.     if (*Selection) {
  146.             if ((charfile = fopen(Filename,"r")) != NULL)
  147.                  fread((char *)characters,sizeof(struct Character),MAXCHARS,charfile);
  148.             else {
  149.                printf("File not found\n");
  150.                InitChars();
  151.             }
  152.        }
  153.     fclose(charfile);
  154.     PrintChars();
  155.     SetGads();
  156.     ActivateGadget(&Name,wG,NULL);
  157.     return(0);
  158. }
  159.  
  160. /*Write current characters to file using ARP File req. Called from
  161.   edit window.*/
  162. WriteEditFile()
  163. {
  164.     FILE *charfile;
  165.     char *Selection;
  166.  
  167.     if ( Selection = FileRequest(&FR))
  168.         if (*Selection) {
  169.             if ((charfile = fopen(Filename,"w")) != NULL)
  170.                 fwrite((char *)characters,sizeof(struct Character),MAXCHARS,charfile);
  171.             else
  172.                 printf("Panic! Could not open output file\n");
  173.         }
  174.     fclose(charfile);
  175.     return(0);
  176. }
  177.  
  178. /* Initialize singly linked list for extra file display */
  179. InitList()
  180. {
  181.      short i;
  182.  
  183.      for (i=0; i < MAXCHARS-1; i++) {
  184.            CharList[i].link = &CharList[i+1];
  185.            CharList[i].character = &PatchChars[i];
  186.            CharList[i].index = i;
  187.            }
  188.      CharList[MAXCHARS-1].link = NULL;
  189.      CharList[MAXCHARS-1].character = &PatchChars[MAXCHARS-1];
  190.      CharList[MAXCHARS-1].index = MAXCHARS-1;
  191. }
  192.  
  193. /* Hilight selected character from extra file display list */
  194. void updatelistitem(rp,item,x,y,hi)
  195. struct RastPort *rp;
  196. struct CharListItem *item;
  197. long x,y,hi;
  198. {
  199.    static struct IntuiText it = {0,0,JAM2,0,0,0,0,0};
  200.  
  201.    if (hi) {
  202.       it.FrontPen = 0;
  203.       it.BackPen = 1;
  204.       }
  205.    else {
  206.       it.FrontPen = 1;
  207.       it.BackPen = 0;
  208.       }
  209.    it.IText = PatchChars[item->index].Name;
  210.    PrintIText(rp,&it,x,y);
  211. }
  212.  
  213. static struct ListInfo windowlist = {
  214.    445,122,123,50,8,
  215.    50,51,52,53,
  216.    1,0,
  217.    0,0,0,
  218.    0,
  219.    0,0,0,0,
  220.    updatelistitem,
  221.    0,0,0,0,
  222. };
  223.  
  224. /* Read in extra file and display in Inovatools1 list */
  225. ReadPatchFile()
  226. {
  227.     FILE *charfile;
  228.     char *Selection;
  229.  
  230.     if ( Selection = FileRequest(&FR))
  231.     if (*Selection) 
  232.             if ((charfile = fopen(Filename,"r")) != NULL)
  233.                  fread((char *)PatchChars,sizeof(struct Character),MAXCHARS,charfile);
  234.             else 
  235.                printf("File not found\n");
  236.     fclose(charfile);
  237.     windowlist.TopItem = &CharList[0];
  238.     windowlist.TopDisplayItem = &CharList[0];
  239.     DrawList(&windowlist);
  240.     return(0);
  241. }
  242.  
  243. /* Copy extra file character to current character and redisplay gadgets */      
  244. Paste(gad)
  245. struct Gadget *gad;
  246. {
  247.      characters[CurChar] = *PasteChar;
  248.      SetGads();
  249.      ActivateGadget(&Name,wG,NULL);
  250. }
  251.  
  252. /* NextChar() - advance to next character in edit list. Wrap around if
  253.    at end of list. */
  254. NextChar()
  255. {
  256.         if (CurChar < MAXCHARS-1)
  257.                 CurChar++;
  258.     else
  259.         CurChar = 0;
  260.         SetGads(); /*Reset Gadgets to new character*/
  261.     ActivateGadget(&Name,wG,NULL); /*Activate first string gadget*/
  262.     return(0);
  263. }
  264.  
  265. /* PrevChar() - move to previous character in edit list. Wrap around if
  266.    at beginning of list. */
  267. PrevChar()
  268. {
  269.         if (CurChar > 0)
  270.                 CurChar--;
  271.     else
  272.         CurChar = MAXCHARS-1;
  273.         SetGads(); /*Reset gadgets to new character*/
  274.     ActivateGadget(&Name,wG,NULL); /*Activate first string gadget*/
  275.     return(0);
  276. }
  277.  
  278. /* Initialize character array*/
  279. InitChars()
  280. {
  281.         USHORT i;
  282.  
  283.         for (i=0;i<MAXCHARS;i++) {
  284.                 sprintf(characters[i].Name,"Character %d",i);
  285.                 characters[i].AC = 10;
  286.                 characters[i].Level = 1;
  287.                 characters[i].Size = SMALL;
  288.                 characters[i].Job = FIGHTER;
  289.                 characters[i].LgHitPlus = 0;
  290.                 characters[i].SmHitPlus = 0;
  291.                 characters[i].LgDamPlus = 0;
  292.                 characters[i].SmDamPlus = 0;
  293.                 characters[i].LgTypeDie = 6;
  294.                 characters[i].LgNumDie = 1;
  295.                 characters[i].SmTypeDie = 6;
  296.                 characters[i].SmNumDie = 1;
  297.                 SetSave(i);
  298.         }
  299.     return(0);
  300. }
  301.  
  302. /* Set up an integer gadget. For Intuition
  303.    to recognize changes, gadget must first be removed from list. */
  304. SetIntGad(gad,setting)
  305. struct Gadget *gad; /* Which gadget to set up*/
  306. long int setting; /* Value to place into gadget*/
  307. {
  308.         USHORT i;
  309.         struct StringInfo *sinfo;
  310.  
  311.         i = RemoveGadget(wG,gad);
  312.         if (i >= 0) {
  313.                 sinfo = (struct StringInfo *)gad->SpecialInfo;
  314.                 sinfo->LongInt = setting; /* Integer value*/
  315.                 sprintf(sinfo->Buffer,"%d",sinfo->LongInt); /* Put text version*/
  316.                 AddGadget(wG,gad,i); /*Back in windows gadget list*/
  317.         }
  318.         else
  319.                 printf("Panic -- gadget not in list!!\n");
  320.     return(0);
  321. }
  322.  
  323. /* Set up a boolean gadget. For Intuition to recognize changes, gadget
  324.    must first be removed from list.*/
  325. SetBoolGad(gad,setting,constant)
  326. struct Gadget *gad; /* Which gadget to set up*/
  327. int setting,constant; /* Since the gadgets are mutually exclusive need
  328.                       variable setting and setting of gadget. If gadget
  329.                       corresponds to the variable, then select the gadget.*/
  330. {
  331.         USHORT i;
  332.  
  333.         i = RemoveGadget(wG,gad);
  334.         if (i >= 0) {
  335.                 if (setting == constant)
  336.                 /*      gad->Flags |= SELECTED;*/
  337.                         SelectGadget(gad,wG,NULL);
  338.                 else
  339.                 /*      gad->Flags &= ~SELECTED;*/
  340.                         UnSelectGadget(gad,wG,NULL);
  341.                 AddGadget(wG,gad,i);
  342.         }
  343.     return(0);
  344. }
  345.  
  346. /* Set up gadgets for current character */
  347. SetGads()
  348. {
  349.         USHORT i;
  350.  
  351.         i = RemoveGadget(wG,&Name);
  352.         if (i >= 0) {
  353.                 strcpy(NameSIBuff,characters[CurChar].Name);
  354.                 AddGadget(wG,&Name,i);
  355.         }
  356.         SetIntGad(&ArmorClass,characters[CurChar].AC);
  357.         SetBoolGad(&Fighter,characters[CurChar].Job,FIGHTER);
  358.         SetBoolGad(&Cleric,characters[CurChar].Job,CLERIC);
  359.         SetBoolGad(&Thief,characters[CurChar].Job,THIEF);
  360.         SetBoolGad(&MagicUser,characters[CurChar].Job,MAGICUSER);
  361.         SetBoolGad(&Monster,characters[CurChar].Job,MONSTER);
  362.         SetBoolGad(&Small,characters[CurChar].Size,SMALL);
  363.         SetBoolGad(&Large,characters[CurChar].Size,LARGE);
  364.         SetIntGad(&Level,characters[CurChar].Level);
  365.         SetIntGad(&SmHitPlus,characters[CurChar].SmHitPlus);
  366.         SetIntGad(&SmNumDie,characters[CurChar].SmNumDie);
  367.         SetIntGad(&SmDamPlus,characters[CurChar].SmDamPlus);
  368.         SetIntGad(&SmSizeDie,characters[CurChar].SmTypeDie);
  369.         SetIntGad(&LgHitPlus,characters[CurChar].LgHitPlus);
  370.         SetIntGad(&LgDamPlus,characters[CurChar].LgDamPlus);
  371.         SetIntGad(&LgNumDie,characters[CurChar].LgNumDie);
  372.         SetIntGad(&LgSizeDie,characters[CurChar].LgTypeDie);
  373.         SetBoolGad(&ML1,characters[CurChar].Level,ML1.GadgetID);
  374.         SetBoolGad(&ML2,characters[CurChar].Level,ML2.GadgetID);
  375.         SetBoolGad(&ML3,characters[CurChar].Level,ML3.GadgetID);
  376.         SetBoolGad(&ML4,characters[CurChar].Level,ML4.GadgetID);
  377.         SetBoolGad(&ML5,characters[CurChar].Level,ML5.GadgetID);
  378.         SetBoolGad(&ML6,characters[CurChar].Level,ML6.GadgetID);
  379.         SetBoolGad(&ML7,characters[CurChar].Level,ML7.GadgetID);
  380.         SetBoolGad(&ML8,characters[CurChar].Level,ML8.GadgetID);
  381.         SetBoolGad(&ML9,characters[CurChar].Level,ML9.GadgetID);
  382.         SetBoolGad(&ML10,characters[CurChar].Level,ML10.GadgetID);
  383.         SetBoolGad(&ML11,characters[CurChar].Level,ML11.GadgetID);
  384.         SetBoolGad(&ML12,characters[CurChar].Level,ML12.GadgetID);
  385.         SetIntGad(&ParSave,characters[CurChar].Saves[PAR]);
  386.         SetIntGad(&PetSave,characters[CurChar].Saves[PET]);
  387.         SetIntGad(&RodSave,characters[CurChar].Saves[ROD]);
  388.         SetIntGad(&BreathSave,characters[CurChar].Saves[BREATH]);
  389.         SetIntGad(&SpellSave,characters[CurChar].Saves[SPELL]);
  390.         RefreshGadgets(&Name,wG,NULL); /* Redraw them!*/
  391.     return(0);
  392. }
  393.  
  394. /* For PW event handler */
  395. static quit(object)
  396. APTR object;
  397. {
  398.         quit_flag = TRUE;
  399.     return(0);
  400. }
  401.  
  402.  
  403. struct Window *OpenWindow();
  404.  
  405. /* User selected Paralyzation save, so update character array*/
  406. Par(gad)
  407. struct Gadget *gad;
  408. {
  409.      struct StringInfo *sinfo;
  410.      
  411.      sinfo = (struct StringInfo *)gad->SpecialInfo;
  412.      characters[CurChar].Saves[PAR] = sinfo->LongInt;
  413.      ActivateGadget(&PetSave,wG,NULL); /*Advance to next string gadget*/
  414.      return(0);
  415. }    
  416.  
  417. /* User selected Petrification save, so update character array*/
  418. Pet(gad)
  419. struct Gadget *gad;
  420. {
  421.      struct StringInfo *sinfo;
  422.  
  423.      sinfo = (struct StringInfo *)gad->SpecialInfo;
  424.      characters[CurChar].Saves[PET] = sinfo->LongInt;
  425.      ActivateGadget(&RodSave,wG,NULL); /*Advance to next string gadget*/
  426.      return(0);
  427. }
  428.  
  429. /* User selected Rod save, so update character array*/
  430. Rod(gad)
  431. struct Gadget *gad;
  432. {
  433.      struct StringInfo *sinfo;
  434.  
  435.      sinfo = (struct StringInfo *)gad->SpecialInfo;
  436.      characters[CurChar].Saves[ROD] = sinfo->LongInt;
  437.      ActivateGadget(&BreathSave,wG,NULL); /*Advance to next string gadget*/
  438.      return(0);
  439. }
  440.  
  441. /* User selected Breath save, so update character array*/
  442. Breath(gad)
  443. struct Gadget *gad;
  444. {
  445.      struct StringInfo *sinfo;
  446.  
  447.      sinfo = (struct StringInfo *)gad->SpecialInfo;
  448.      characters[CurChar].Saves[BREATH] = sinfo->LongInt;
  449.      ActivateGadget(&SpellSave,wG,NULL); /*Advance to next string gadget*/
  450.      return(0);
  451. }
  452.  
  453. /* User selected Spell save, so update character array*/
  454. Spell(gad)
  455. struct Gadget *gad;
  456. {
  457.      struct StringInfo *sinfo;
  458.    
  459.      sinfo = (struct StringInfo *)gad->SpecialInfo;
  460.      characters[CurChar].Saves[SPELL] = sinfo->LongInt;
  461.      NextChar(); /*Last gadget, advance to next charcter*/
  462.      return(0);
  463. }
  464.  
  465. /* User selected name gadget, so update character array*/
  466. AddName(gad)
  467. struct Gadget  *gad;
  468. {
  469.         struct StringInfo *sinfo;
  470.  
  471.         sinfo = (struct StringInfo *)gad->SpecialInfo;
  472.         strcpy(characters[CurChar].Name,sinfo->Buffer);
  473.     ActivateGadget(&Level,wG,NULL); /*Advance to next string gadget*/
  474.     return(0);
  475. }
  476.  
  477. /* User selected AC gadget, so update character array*/
  478. AddAC(gad)
  479. struct Gadget  *gad;
  480. {
  481.         struct StringInfo *sinfo;
  482.  
  483.         sinfo = (struct StringInfo *)gad->SpecialInfo;
  484.         characters[CurChar].AC = sinfo->LongInt;
  485.     ActivateGadget(&SmHitPlus,wG,NULL); /* Advance to next string gadget*/    
  486.     return(0);
  487. }
  488.  
  489. /* User changed class of character, so update character array*/
  490. SelectJob(gad)
  491. struct Gadget  *gad;
  492. {
  493.         characters[CurChar].Job = gad->GadgetID;
  494.     SetSave(CurChar); /* Job affects saving throws */
  495.         SetSaveGads(CurChar);
  496.         return(0);
  497. }
  498.  
  499. /* User changed size of character, so update character array*/
  500. ReSize(gad)
  501. struct Gadget  *gad;
  502. {
  503.         characters[CurChar].Size = gad->GadgetID;
  504.     return(0);
  505. }
  506.  
  507. /* User changed level of character, so update character array*/
  508. ChangeLevel(gad)
  509. struct Gadget  *gad;
  510. {
  511.         struct StringInfo *sinfo;
  512.  
  513.         sinfo = (struct StringInfo *)gad->SpecialInfo;
  514.         characters[CurChar].Level = sinfo->LongInt;
  515.     ActivateGadget(&ArmorClass,wG,NULL); /*Advance to next string gadget*/
  516.     SetSave(CurChar); /* Job affects saving throws*/
  517.         SetSaveGads(CurChar);
  518.         return(0);
  519. }
  520.  
  521. /* User changed to hit small, update character array*/
  522. SmHit(gad)
  523. struct Gadget  *gad;
  524. {
  525.         struct StringInfo *sinfo;
  526.  
  527.         sinfo = (struct StringInfo *)gad->SpecialInfo;
  528.         characters[CurChar].SmHitPlus = sinfo->LongInt;
  529.     ActivateGadget(&SmNumDie,wG,NULL); /*Advance to next string gadget*/
  530.     return(0);
  531. }
  532.  
  533. /* User changed hit dice, update character array*/
  534. HitDice(gad)
  535. struct Gadget *gad;
  536. {
  537.         struct StringInfo *sinfo;
  538.  
  539.         sinfo = (struct StringInfo *)gad->SpecialInfo;
  540.         characters[CurChar].Level = gad->GadgetID; /*Change level gadget*/
  541.         SetIntGad(&Level,characters[CurChar].Level);
  542.         SetSave(CurChar); /*Hit dice affects save*/
  543.         SetSaveGads(CurChar);
  544.            
  545.     return(0);
  546. }
  547.  
  548. /* User changed number of dice vs. small, update character array*/
  549. SmNum(gad)
  550. struct Gadget  *gad;
  551. {
  552.         struct StringInfo *sinfo;
  553.  
  554.         sinfo = (struct StringInfo *)gad->SpecialInfo;
  555.         characters[CurChar].SmNumDie = sinfo->LongInt;
  556.     ActivateGadget(&SmDamPlus,wG,NULL);/*Advance to next string gadget*/
  557.     return(0);
  558. }
  559.  
  560. /* User changed damage plus vs. small, update character array*/
  561. SmDam(gad)
  562. struct Gadget  *gad;
  563. {
  564.         struct StringInfo *sinfo;
  565.  
  566.         sinfo = (struct StringInfo *)gad->SpecialInfo;
  567.         characters[CurChar].SmDamPlus = sinfo->LongInt;
  568.     ActivateGadget(&SmSizeDie,wG,NULL);/*Advance to next string gadget*/
  569.     return(0);
  570. }
  571.  
  572. /* User changed type of die vs. small, update character array*/
  573. SmSize(gad)
  574. struct Gadget  *gad;
  575. {
  576.         struct StringInfo *sinfo;
  577.  
  578.         sinfo = (struct StringInfo *)gad->SpecialInfo;
  579.         characters[CurChar].SmTypeDie = sinfo->LongInt;
  580.     ActivateGadget(&LgHitPlus,wG,NULL);/*Advance to next string gadget*/
  581.     return(0);
  582. }
  583.  
  584. /* User changed hit bonus vs. large, update character array*/
  585. LgHit(gad)
  586. struct Gadget  *gad;
  587. {
  588.         struct StringInfo *sinfo;
  589.  
  590.         sinfo = (struct StringInfo *)gad->SpecialInfo;
  591.         characters[CurChar].LgHitPlus = sinfo->LongInt;
  592.     ActivateGadget(&LgNumDie,wG,NULL);/*Advance to next string gadget*/
  593.     return(0);
  594. }
  595.  
  596. /* User changed damage bonus vs. large, update character array*/
  597. LgDam(gad)
  598. struct Gadget  *gad;
  599. {
  600.         struct StringInfo *sinfo;
  601.  
  602.         sinfo = (struct StringInfo *)gad->SpecialInfo;
  603.         characters[CurChar].LgDamPlus = sinfo->LongInt;
  604.     ActivateGadget(&LgSizeDie,wG,NULL);/*Advance to next string gadget*/
  605.     return(0);
  606. }
  607.  
  608. /* User changed num. of dice vs. large, update character array*/
  609. LgNum(gad)
  610. struct Gadget  *gad;
  611. {
  612.         struct StringInfo *sinfo;
  613.  
  614.         sinfo = (struct StringInfo *)gad->SpecialInfo;
  615.         characters[CurChar].LgNumDie = sinfo->LongInt;
  616.     ActivateGadget(&LgDamPlus,wG,NULL);/*Advance to next string gadget*/
  617.     return(0);
  618. }
  619.  
  620. /* User changed size of die vs. large, update character array*/
  621. LgSize(gad)
  622. struct Gadget  *gad;
  623. {
  624.         struct StringInfo *sinfo;
  625.  
  626.         sinfo = (struct StringInfo *)gad->SpecialInfo;
  627.         characters[CurChar].LgTypeDie = sinfo->LongInt;
  628.     ActivateGadget(&ParSave,wG,NULL); /*Advance to next string gadget*/
  629.     return(0);
  630. }
  631.  
  632. /* End editing session */
  633. QuitEdit(gad)
  634. struct Gadget  *gad;
  635. {
  636.     PrintChars(); /* Print characters on combat window*/
  637.         quit(gad);
  638.     return(0);
  639. }
  640.  
  641. /* Determine row of save table for fighter */
  642. FighterSaveRow(level)
  643. int level;
  644. {
  645.      int row;
  646.    
  647.      if (level <1 )
  648.          row = 0;
  649.      else if (level > 16)
  650.          row = 9;
  651.      else
  652.          row = ((level+1)/2);
  653.      return(row);
  654. }
  655.  
  656. /* Determine row of save table for cleric */
  657. ClericSaveRow(level)
  658. int level;
  659. {
  660.      int row;
  661.  
  662.      if (level > 18)
  663.           row = 6;
  664.      else if (level < 1)
  665.           row = 0;
  666.      else
  667.           row = ((level-1)/3);
  668.      return(row);
  669. }
  670.  
  671. /* Determine row of save table for Magic users */
  672. MagicSaveRow(level)
  673. int level;
  674. {
  675.      int row;
  676.  
  677.      if (level < 1)
  678.           row = 0;
  679.      else if (level > 20)
  680.           row = 4;
  681.      else
  682.           row = ((level-1)/5);
  683.      return(row);
  684. }
  685.  
  686. /*Determine row of save table for thief */
  687. ThiefSaveRow(level)
  688. int level;
  689. {
  690.      int row;
  691.     
  692.      if (level < 1)
  693.           row = 0;
  694.      else if (level > 20)
  695.           row = 5;
  696.      else
  697.           row = ((level-1)/4);
  698.      return(row);
  699. }
  700.  
  701. /* Determine row of save table for monster */
  702. /* Note that this is an approximation. See Dungeon Master's 
  703. Guide to make neccesary adjustments */
  704. MonsterSaveRow(level)
  705. int level;
  706. {
  707.      int row;
  708.  
  709.      if (level < 2)
  710.           row = 0;
  711.      else if (level < 5)
  712.           row = 1;
  713.      else if (level > 12)
  714.           row = 9;
  715.      else 
  716.           row = (level-3);
  717.      return(row);
  718. }
  719.  
  720.               
  721.  
  722. /* User selected new level/hd or job, so modify saves */
  723. SetSave(Char)
  724. int Char;
  725. {
  726.      int save,row,level;
  727.  
  728.      level = characters[Char].Level;
  729.      switch(characters[Char].Job) {
  730.           case FIGHTER : { 
  731.                            row = FighterSaveRow(level);
  732.                            save = FighterSave[row][PAR];
  733.                            characters[Char].Saves[PAR] = save;
  734.                            save = FighterSave[row][PET];
  735.                            characters[Char].Saves[PET] = save;
  736.                            save = FighterSave[row][ROD];
  737.                            characters[Char].Saves[ROD] = save;
  738.                            save = FighterSave[row][BREATH];
  739.                            characters[Char].Saves[BREATH] = save;
  740.                            save = FighterSave[row][SPELL];
  741.                            characters[Char].Saves[SPELL] = save;
  742.                            break;
  743.                          }
  744.           case CLERIC :  { 
  745.                            row = ClericSaveRow(level);
  746.                            save = ClericSave[row][PAR];
  747.                            characters[Char].Saves[PAR] = save;
  748.                            save = ClericSave[row][PET];
  749.                            characters[Char].Saves[PET] = save;
  750.                            save = ClericSave[row][ROD];
  751.                            characters[Char].Saves[ROD] = save;
  752.                            save = ClericSave[row][BREATH];
  753.                            characters[Char].Saves[BREATH] = save;
  754.                            save = ClericSave[row][SPELL];
  755.                            characters[Char].Saves[SPELL] = save;
  756.                            break;
  757.                          }
  758.           case MAGICUSER :{
  759.                            row = MagicSaveRow(level);
  760.                            save = MagicSave[row][PAR];
  761.                            characters[Char].Saves[PAR] = save;
  762.                            save = MagicSave[row][PET];
  763.                            characters[Char].Saves[PET] = save;
  764.                            save = MagicSave[row][ROD];
  765.                            characters[Char].Saves[ROD] = save;
  766.                            save = MagicSave[row][BREATH];
  767.                            characters[Char].Saves[BREATH] = save;
  768.                            save = MagicSave[row][SPELL];
  769.                            characters[Char].Saves[SPELL] = save;
  770.                            break;
  771.                          }
  772.           case THIEF :   { 
  773.                            row = ThiefSaveRow(level);
  774.                            save = ThiefSave[row][PAR];
  775.                            characters[Char].Saves[PAR] = save;
  776.                            save = ThiefSave[row][PET];
  777.                            characters[Char].Saves[PET] = save;
  778.                            save = ThiefSave[row][ROD];
  779.                            characters[Char].Saves[ROD] = save;
  780.                            save = ThiefSave[row][BREATH];
  781.                            characters[Char].Saves[BREATH] = save;
  782.                            save = ThiefSave[row][SPELL];
  783.                            characters[Char].Saves[SPELL] = save;
  784.                            break;
  785.                          }
  786.           case MONSTER : { 
  787.                            row = MonsterSaveRow(level);
  788.                            save = FighterSave[row][PAR];
  789.                            characters[Char].Saves[PAR] = save;
  790.                            save = FighterSave[row][PET];
  791.                            characters[Char].Saves[PET] = save;
  792.                            save = FighterSave[row][ROD];
  793.                            characters[Char].Saves[ROD] = save;
  794.                            save = FighterSave[row][BREATH];
  795.                            characters[Char].Saves[BREATH] = save;
  796.                            save = FighterSave[row][SPELL];
  797.                            characters[Char].Saves[SPELL] = save;
  798.                            break;
  799.                          }
  800.      }
  801.      return(0);
  802. }
  803.  
  804. SetSaveGads(Char)
  805. int Char;
  806. {
  807.      SetIntGad(&ParSave,characters[Char].Saves[PAR]);
  808.      SetIntGad(&PetSave,characters[Char].Saves[PET]);
  809.      SetIntGad(&RodSave,characters[Char].Saves[ROD]);
  810.      SetIntGad(&BreathSave,characters[Char].Saves[BREATH]);
  811.      SetIntGad(&SpellSave,characters[Char].Saves[SPELL]);
  812.      RefreshGadgets(&Name,wG,NULL);
  813.      return(0);
  814. }
  815.  
  816. /* Main editing event handling and set up routine
  817.    Note: this routine is adapted from the PW example program
  818.    and contains unused remnants thereof. Sorry, but I am lazy.  */
  819. Edit()
  820. {
  821.         UWORD code;
  822.         ULONG class;
  823.         struct Gadget *object;
  824.     extern long IntuitionBase;
  825.     extern long  GfxBase;
  826.         struct CharListItem *litem;
  827.         struct RastPort *rpG;
  828.         struct IntuiMessage *message;   /* the message the IDCMP sends us */
  829.         if (IntuitionBase == NULL)
  830.             IntuitionBase = OpenLibrary("intuition.library", 0);
  831.         if (IntuitionBase == NULL)
  832.         {
  833.                 printf("intuition is not here.  where are we?\n");
  834.                 goto cleanup1;
  835.         }
  836.         if (GfxBase == NULL)
  837.             GfxBase = OpenLibrary("graphics.library", 0);
  838.  
  839.         quit_flag = FALSE;
  840.         wG = (struct Window *) MxOpenWindow(&NewWindowStructure1);
  841.         if ( wG == NULL )
  842.         {
  843.                 printf ("open window failed\n");
  844.                 goto cleanup1;
  845.         }
  846.         InitList();
  847.         windowlist.Window = wG;
  848.         InitListInfo(&windowlist);
  849.     SetGads(); /* Set up initial display */
  850.         rpG = wG->RPort;        /* get a rastport pointer for the window */
  851.  
  852.     DrawBorder(rpG,&BorderList1,0,0);
  853.         PrintIText(rpG,&IntuiTextList1,0,0);   
  854.     ActivateWindow(wG);
  855.         do
  856.         {
  857.                 WaitPort(wG->UserPort);
  858.                         while( (message = (struct IntuiMessage *)
  859.                                 GetMsg(wG->UserPort) ) != NULL)
  860.                         {
  861.                                 code = message->Code;  /* MENUNUM */
  862.                                 object = (struct Gadget *)message->IAddress;  /* Gadget */
  863.                                 class = message->Class;
  864.                                 ReplyMsg(message);
  865.                 if ( class == ACTIVEWINDOW) 
  866.                     ActivateGadget(&Name,wG,NULL);
  867.                                 if ( class == CLOSEWINDOW ) 
  868.                                         QuitEdit(object);
  869.                                 if ( class == GADGETDOWN ){
  870.                                    if (object->GadgetID == 51) { 
  871.                                            litem = (struct CharListItem *)GetListItem(&windowlist);
  872.                                            PasteChar = litem->character;
  873.                                    }
  874.                                    else if ((object->GadgetID == 52)||(object->GadgetID == 53)) 
  875.                                            ClickList(&windowlist,object->GadgetID);
  876.                                    }
  877.                                 if (class == GADGETUP) {
  878.                                    if (object->GadgetID == 50)
  879.                                       ScrollList(&windowlist);
  880.                                 else {
  881.                                    HandleEditEvent(object);
  882.                                    SelectGadget(object,wG,NULL);
  883.                                 }
  884.                             }
  885.                         }
  886.         } while (quit_flag == FALSE);
  887.  
  888. cleanup3:
  889.  
  890. cleanup2:
  891.         RemoveListInfo(&windowlist);
  892.         MxCloseWindow(wG);
  893.  
  894. cleanup1:
  895.         return(0);
  896. }
  897.