home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / game / think / chaos / src / roundsami.c < prev   
Encoding:
C/C++ Source or Header  |  1993-12-07  |  12.7 KB  |  432 lines

  1. /*  Chaos:            The Chess HAppening Organisation System    V5.2
  2.     Copyright (C)   1993    Jochen Wiedmann
  3.  
  4.     This program is free software; you can redistribute it and/or modify
  5.     it under the terms of the GNU General Public License as published by
  6.     the Free Software Foundation; either version 2 of the License, or
  7.     (at your option) any later version.
  8.  
  9.     This program is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.     GNU General Public License for more details.
  13.  
  14.     You should have received a copy of the GNU General Public License
  15.     along with this program; if not, write to the Free Software
  16.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18.  
  19.     $RCSfile: RoundsWnd.c,v $
  20.     $Revision: 2.4 $
  21.     $Date: 1993/11/20 15:52:15 $
  22.  
  23.     This file contains the system dependent part of the functions to enter
  24.     results.
  25.  
  26.     Computer:    Amiga 1200            Compiler:    Dice 2.07.54 (3.0)
  27.  
  28.     Author:    Jochen Wiedmann
  29.         Am Eisteich 9
  30.       72555 Metzingen
  31.         Tel. 07123 / 14881
  32.         Internet: wiedmann@mailserv.zdv.uni-tuebingen.de
  33. */
  34.  
  35.  
  36. #ifndef CHAOS_H
  37. #include "chaos.h"
  38. #endif
  39.  
  40.  
  41.  
  42.  
  43. /*
  44.     GetRoundNr() allows the user to select a round.
  45.  
  46.     Result: round number or 0, if the user cancels
  47. */
  48. #define ID_RndSelWnd_Ok     20
  49. #define ID_RndSelWnd_Cancel    21
  50. #define ID_RndselWnd_Rnd    22
  51.  
  52.  
  53. int GetRoundNr(void)
  54.  
  55. #ifdef AMIGA
  56. { ULONG open, signal;
  57.   int round = 0;
  58.   APTR RndSelWnd;        /*    round select window            */
  59.   APTR RndSelWnd_Ok;        /*    Ok button (round select window)     */
  60.   APTR RndSelWnd_Cancel;    /*    Cancel button (round select window) */
  61.   APTR RndSelWnd_Rnd;        /*    round number gadget            */
  62.  
  63.   if (NumRounds == 1)
  64.   { return(1);
  65.   }
  66.  
  67.   RndSelWnd = WindowObject,
  68.         MUIA_Window_ID, MAKE_ID('R','N','D','S'),
  69.         MUIA_Window_Title, GetChaosString(WND_RNDSEL_TITLE),
  70.         MUIA_Window_DefaultObject, RndSelWnd_Rnd,
  71.         WindowContents, VGroup,
  72.             Child, TextObject,
  73.             MUIA_Text_Contents, GetChaosString(WND_RNDSEL_TEXT),
  74.             End,
  75.             Child, RndSelWnd_Rnd = SliderObject,
  76.             MUIA_Slider_Max, NumRounds,
  77.             MUIA_Slider_Level, NumRounds,
  78.             MUIA_Slider_Min, 1,
  79.             End,
  80.             Child, HGroup,
  81.             Child, RndSelWnd_Ok = KeyButton(GetChaosString(MSG_OK), *GetChaosString(MSG_OK_SC)),
  82.             Child, RndSelWnd_Cancel = KeyButton(GetChaosString(MSG_CANCEL_INPUT), *GetChaosString(MSG_CANCEL_SC)),
  83.             End,
  84.         End,
  85.         End;
  86.  
  87.   if (!RndSelWnd)
  88.   { return(0);
  89.   }
  90.   DoMethod(App, OM_ADDMEMBER, RndSelWnd);
  91.   DoMethod(RndSelWnd, MUIM_Window_SetCycleChain, RndSelWnd_Rnd,
  92.        RndSelWnd_Ok, RndSelWnd_Cancel, NULL);
  93.  
  94.   /*
  95.       Setting up the notification events for the round select window:
  96.       CloseWindow, Ok-, and Cancel-button and the round number gadget.
  97.   */
  98.   DoMethod(RndSelWnd, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
  99.        App, 2, MUIM_Application_ReturnID, ID_RndSelWnd_Cancel);
  100.   DoMethod(RndSelWnd_Cancel, MUIM_Notify, MUIA_Pressed, FALSE, App, 2,
  101.        MUIM_Application_ReturnID, ID_RndSelWnd_Cancel);
  102.   DoMethod(RndSelWnd, MUIM_Notify, MUIA_Window_InputEvent, "ctrl return",
  103.        App, 2, MUIM_Application_ReturnID, ID_RndSelWnd_Ok);
  104.   DoMethod(RndSelWnd_Ok, MUIM_Notify, MUIA_Pressed, FALSE,
  105.        App, 2, MUIM_Application_ReturnID, ID_RndSelWnd_Ok);
  106.  
  107.   set(MainWnd, MUIA_Window_Open, FALSE);
  108.   set(RndSelWnd, MUIA_Window_Open, TRUE);
  109.   get(RndSelWnd, MUIA_Window_Open, &open);
  110.   if (!open)
  111.   { MUIError((char *) GetChaosString(ERRMSG_CANNOT_OPEN_WINDOW));
  112.     DoMethod(App, OM_REMMEMBER, RndSelWnd);
  113.     MUI_DisposeObject(RndSelWnd);
  114.     return(0);
  115.   }
  116.  
  117.   for(;;)
  118.   { switch(DoMethod(App, MUIM_Application_Input, &signal))
  119.     { case MUIV_Application_ReturnID_Quit:
  120.     if (TestSaved())
  121.     { Cleanup(0, NULL);
  122.     }
  123.     break;
  124.       case ID_RndSelWnd_Ok:
  125.     get(RndSelWnd_Rnd, MUIA_Slider_Level, &round);
  126.       case ID_RndSelWnd_Cancel:
  127.     set(RndSelWnd, MUIA_Window_Open, FALSE);
  128.     DoMethod(App, OM_REMMEMBER, RndSelWnd);
  129.     MUI_DisposeObject(RndSelWnd);
  130.     return(round);
  131.     }
  132.  
  133.     if (signal)
  134.     { Wait(signal);
  135.     }
  136.   }
  137. }
  138. #endif    /*  AMIGA   */
  139.  
  140.  
  141.  
  142.  
  143. /*
  144.     TerminateRsltWnd() closes the result window.
  145. */
  146. #ifdef AMIGA
  147. static APTR RsltWnd = NULL;    /*  Result window            */
  148. static APTR RsltWnd_OkGad;    /*  Ok button (result window)           */
  149. static APTR RsltWnd_CancelGad;    /*  Cancel button (result window)       */
  150. static APTR RsltWnd_GmLV;    /*  game listview gadget (result window)*/
  151. static APTR RsltWnd_Rslt;    /*  result radio gadget         */
  152. static APTR RsltWnd_Mode;    /*  result mode radio gadget        */
  153.  
  154. void TerminateRsltWnd(void)
  155.  
  156. { if (RsltWnd)
  157.   { set(RsltWnd, MUIA_Window_Open, FALSE);
  158.     DoMethod(App, OM_REMMEMBER, RsltWnd);
  159.     MUI_DisposeObject(RsltWnd);
  160.     RsltWnd = NULL;
  161.   }
  162. }
  163. #endif    /*  AMIGA   */
  164.  
  165.  
  166.  
  167.  
  168. #ifdef AMIGA
  169. /*
  170.     This is the MUI-displayhook. The following function gets called, when
  171.     a game is displayed.
  172. */
  173. SAVEDS ASM static LONG DispRsltFunc(REG(a1) struct GameNode *gn,
  174.                     REG(a2) char **array)
  175.  
  176. {
  177.   *array++ = gn->Text;
  178.   *array++ = gn->White->Name;
  179.   *array++ = ": ";
  180.   *array++ = gn->Black->Name;
  181.   *array   = gn->Text + strlen(gn->Text) + 1;
  182.   return(0);
  183. }
  184. #ifdef AZTEC_C
  185. extern LONG MyDispRsltFunc (struct GameNode *gn, char **array);
  186. #asm
  187.         xref    _geta4
  188. _MyDispRsltFunc:
  189.         move.l    a4,-(sp)
  190.         jsr    _geta4
  191.         move.l    a2,-(sp)
  192.         move.l    a1,-(sp)
  193.         jsr    _DispRsltFunc
  194.         add.l    #8,sp
  195.         move.l    (sp)+,a4
  196.         rts
  197. #endasm
  198. #define DispRsltFunc MyDispRsltFunc
  199. #endif    /*  AZTEC_C */
  200. struct Hook RsltWnd_GmListDispHook =
  201. { NULL, NULL, (void *) DispRsltFunc, NULL, NULL
  202. };
  203. #endif    /*  AMIGA   */
  204.  
  205.  
  206.  
  207.  
  208. /*
  209.     InitRsltWnd() initializes the window to enter results.
  210.  
  211.     Inputs: title   - window title
  212.         rlist   - list of GameNode structures created using GetRound()
  213.  
  214.     Result: TRUE, if successfull, FALSE otherwise
  215. */
  216. #ifdef AMIGA
  217. #define ID_RsltWnd_Ok        14
  218. #define ID_RsltWnd_Cancel    15
  219. #define ID_RsltWnd_Rslt     16
  220. #define ID_RsltWnd_Mode     17
  221. #define ID_RsltWnd_GmLV     18
  222. #define ID_RsltWnd_White    23
  223. #define ID_RsltWnd_Draw     24
  224. #define ID_RsltWnd_Black    25
  225. #define ID_RsltWnd_Missing    26
  226. #define ID_RsltWnd_Played    27
  227. #define ID_RsltWnd_NotPlayed    28
  228. #define ID_RsltWnd_Down     29
  229.  
  230. int InitRsltWnd(char *title, struct MinList *rlist)
  231.  
  232. { ULONG open;
  233.   struct GameNode *gn;
  234.   static STRPTR RsltWnd_Rslt_Entries[5];
  235.   static STRPTR RsltWnd_Mode_Entries[3];
  236.  
  237.   RsltWnd_Rslt_Entries[0] = GetChaosString(MSG_WHITE_WINS_INPUT);
  238.   RsltWnd_Rslt_Entries[1] = GetChaosString(MSG_DRAW_INPUT);
  239.   RsltWnd_Rslt_Entries[2] = GetChaosString(MSG_BLACK_WINS_INPUT);
  240.   RsltWnd_Rslt_Entries[3] = GetChaosString(MSG_RESULT_MISSING_INPUT);
  241.   RsltWnd_Rslt_Entries[4] = NULL;
  242.   RsltWnd_Mode_Entries[0] = GetChaosString(MSG_AUSGETRAGEN_INPUT);
  243.   RsltWnd_Mode_Entries[1] = GetChaosString(MSG_KAMPFLOS_INPUT);
  244.   RsltWnd_Mode_Entries[2] = NULL;
  245.  
  246.   RsltWnd = WindowObject,
  247.         MUIA_Window_ID, MAKE_ID('R','S','L','T'),
  248.         MUIA_Window_Title, title,
  249.         MUIA_Window_DefaultObject, RsltWnd_GmLV,
  250.         WindowContents, VGroup,
  251.             Child, RsltWnd_GmLV = ListviewObject,
  252.             MUIA_Listview_List, ListObject,
  253.                 MUIA_List_Format, ",,,,",
  254.                 MUIA_List_DisplayHook, &RsltWnd_GmListDispHook,
  255.                 InputListFrame,
  256.             End,
  257.             End,
  258.             Child, HGroup,
  259.             Child, RsltWnd_OkGad = KeyButton(GetChaosString(MSG_OK), *GetChaosString(MSG_OK_SC)),
  260.             Child, HSpace(10),
  261.             Child, RsltWnd_Rslt = Radio(GetChaosString(RADIO_RESULT_TITLE),
  262.                             RsltWnd_Rslt_Entries),
  263.             Child, RsltWnd_Mode = Radio(GetChaosString(RADIO_MODE_TITLE),
  264.                             RsltWnd_Mode_Entries),
  265.             Child, HSpace(10),
  266.             Child, RsltWnd_CancelGad = KeyButton(GetChaosString(MSG_CANCEL_INPUT), *GetChaosString(MSG_CANCEL_SC)),
  267.             End,
  268.         End,
  269.         End;
  270.  
  271.   if (!RsltWnd)
  272.   { return(FALSE);
  273.   }
  274.   DoMethod(App, OM_ADDMEMBER, RsltWnd);
  275.   DoMethod(RsltWnd, MUIM_Window_SetCycleChain, RsltWnd_GmLV, RsltWnd_OkGad,
  276.        RsltWnd_Rslt, RsltWnd_Mode, RsltWnd_CancelGad, NULL);
  277.  
  278.   /*
  279.       Setting up the notification events for the result window:
  280.       CloseWindow, Ok-, and Cancel-button, the result and result-mode
  281.       gadgets and the result keys.
  282.   */
  283.   DoMethod(RsltWnd, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
  284.        App, 2, MUIM_Application_ReturnID, ID_RsltWnd_Cancel);
  285.   DoMethod(RsltWnd, MUIM_Notify, MUIA_Window_InputEvent, "esc",
  286.        App, 2, MUIM_Application_ReturnID, ID_RsltWnd_Cancel);
  287.   DoMethod(RsltWnd_CancelGad, MUIM_Notify, MUIA_Pressed, FALSE,
  288.        App, 2, MUIM_Application_ReturnID, ID_RsltWnd_Cancel);
  289.   DoMethod(RsltWnd, MUIM_Notify, MUIA_Window_InputEvent, "ctrl return",
  290.        App, 2, MUIM_Application_ReturnID, ID_RsltWnd_Ok);
  291.   DoMethod(RsltWnd_OkGad, MUIM_Notify, MUIA_Pressed, FALSE,
  292.        App, 2, MUIM_Application_ReturnID, ID_RsltWnd_Ok);
  293.   DoMethod(RsltWnd_Rslt, MUIM_Notify, MUIA_Radio_Active, MUIV_EveryTime,
  294.        App, 2, MUIM_Application_ReturnID, ID_RsltWnd_Rslt);
  295.   DoMethod(RsltWnd_Mode, MUIM_Notify, MUIA_Radio_Active, MUIV_EveryTime,
  296.        App, 2, MUIM_Application_ReturnID, ID_RsltWnd_Mode);
  297.   DoMethod(RsltWnd_GmLV, MUIM_Notify, MUIA_List_Active, MUIV_EveryTime,
  298.        App, 2, MUIM_Application_ReturnID, ID_RsltWnd_GmLV);
  299.   DoMethod(RsltWnd, MUIM_Notify, MUIA_Window_InputEvent,
  300.        GetChaosString(KEY_RESULT_WHITE),
  301.        App, 2, MUIM_Application_ReturnID, ID_RsltWnd_White);
  302.   DoMethod(RsltWnd, MUIM_Notify, MUIA_Window_InputEvent,
  303.        GetChaosString(KEY_RESULT_BLACK),
  304.        App, 2, MUIM_Application_ReturnID, ID_RsltWnd_Black);
  305.   DoMethod(RsltWnd, MUIM_Notify, MUIA_Window_InputEvent,
  306.        GetChaosString(KEY_RESULT_MISSING),
  307.        App, 2, MUIM_Application_ReturnID, ID_RsltWnd_Missing);
  308.   DoMethod(RsltWnd, MUIM_Notify, MUIA_Window_InputEvent,
  309.        GetChaosString(KEY_RESULT_DRAW),
  310.        App, 2, MUIM_Application_ReturnID, ID_RsltWnd_Draw);
  311.   DoMethod(RsltWnd, MUIM_Notify, MUIA_Window_InputEvent,
  312.        GetChaosString(KEY_RESULT_PLAYED),
  313.        App, 2, MUIM_Application_ReturnID, ID_RsltWnd_Played);
  314.   DoMethod(RsltWnd, MUIM_Notify, MUIA_Window_InputEvent,
  315.        GetChaosString(KEY_RESULT_NPLAYED),
  316.        App, 2, MUIM_Application_ReturnID, ID_RsltWnd_NotPlayed);
  317.  
  318.   /*
  319.       Initialize the window settings
  320.   */
  321.   gn = (struct GameNode *) rlist->mlh_Head;
  322.   for (gn = (struct GameNode *) rlist->mlh_Head;
  323.        gn->gn_Node.mln_Succ != NULL;
  324.        gn = (struct GameNode *) gn->gn_Node.mln_Succ)
  325.   { DoMethod(RsltWnd_GmLV, MUIM_List_Insert, &gn, 1,
  326.          MUIV_List_Insert_Bottom);
  327.   }
  328.   set(RsltWnd_GmLV, MUIA_List_Active, MUIV_List_Active_Top);
  329.  
  330.  
  331.   set(RsltWnd, MUIA_Window_Open, TRUE);
  332.   get(RsltWnd, MUIA_Window_Open, &open);
  333.   if (!open)
  334.   { MUIError((char *) GetChaosString(ERRMSG_CANNOT_OPEN_WINDOW));
  335.     return(FALSE);
  336.   }
  337.   return(TRUE);
  338. }
  339. #endif
  340.  
  341.  
  342.  
  343.  
  344. /*
  345.     ProcessRsltWnd() allows the user to enter the results.
  346.  
  347.     Input: rlist    - A list of GameNode structures created using
  348.               GetRound(). The function may modify the contents.
  349.  
  350.     Result: -1    - The user has selected the Ok button, process the changes
  351.         1    - Indicates, that ProcessRsltWnd() wants to be called again
  352.         0    - The user has terminated via Cancel button
  353. */
  354. int ProcessRsltWnd(struct MinList *rlist)
  355.  
  356. #ifdef AMIGA
  357. { ULONG Signal, id;
  358.   struct GameNode *gn;
  359.   LONG result, mode;
  360.  
  361.   /*
  362.       Check for user actions
  363.   */
  364.   switch (id = DoMethod(App, MUIM_Application_Input, &Signal))
  365.   { case MUIV_Application_ReturnID_Quit:
  366.       if (TestSaved())
  367.       { Cleanup(0, NULL);
  368.       }
  369.       break;
  370.     case ID_RsltWnd_Cancel:
  371.       return(0);
  372.     case ID_RsltWnd_Ok:
  373.       return(-1);
  374.     case ID_RsltWnd_Rslt:
  375.     case ID_RsltWnd_White:
  376.     case ID_RsltWnd_Draw:
  377.     case ID_RsltWnd_Black:
  378.     case ID_RsltWnd_Missing:
  379.       DoMethod(RsltWnd_GmLV, MUIM_List_GetEntry, MUIV_List_GetEntry_Active,
  380.            &gn);
  381.       if (gn != NULL)
  382.       { if (id == ID_RsltWnd_Rslt)
  383.     { get(RsltWnd_Rslt, MUIA_Radio_Active, &result);
  384.     }
  385.     else
  386.     { result = id - ID_RsltWnd_White;
  387.     }
  388.     gn->Result = 2-result;
  389.     FormatGame(gn, 2);
  390.     DoMethod(RsltWnd_GmLV, MUIM_List_Redraw, MUIV_List_Redraw_Active);
  391.       }
  392.     case ID_RsltWnd_GmLV:
  393.       DoMethod(RsltWnd_GmLV, MUIM_List_GetEntry, MUIV_List_GetEntry_Active,
  394.            &gn);
  395.       if (gn != NULL)
  396.       { set(RsltWnd_Rslt, MUIA_Radio_Active, 2-gn->Result);
  397.     set(RsltWnd_Mode, MUIA_Radio_Active,
  398.         (gn->Flags & GMFLAGSF_NOFIGHT) ? 1 : 0);
  399.       }
  400.       if (id != ID_RsltWnd_Rslt  &&  id != ID_RsltWnd_GmLV)
  401.     { DoMethod(App, MUIM_Application_ReturnID, ID_RsltWnd_Down);
  402.     }
  403.       break;
  404.     case ID_RsltWnd_Down:
  405.       set(RsltWnd_GmLV, MUIA_List_Active, MUIV_List_Active_Down);
  406.       break;
  407.     case ID_RsltWnd_Mode:
  408.     case ID_RsltWnd_Played:
  409.     case ID_RsltWnd_NotPlayed:
  410.       DoMethod(RsltWnd_GmLV, MUIM_List_GetEntry, MUIV_List_GetEntry_Active,
  411.            &gn);
  412.       if (gn != NULL)
  413.       { if (id == ID_RsltWnd_Mode)
  414.       { get(RsltWnd_Mode, MUIA_Radio_Active, &mode);
  415.       }
  416.     else
  417.       { mode = id - ID_RsltWnd_Played;
  418.       }
  419.     gn->Flags = (gn->Flags & ~GMFLAGSF_NOFIGHT) |
  420.             (mode ? GMFLAGSF_NOFIGHT : 0);
  421.     FormatGame(gn, 2);
  422.     DoMethod(RsltWnd_GmLV, MUIM_List_Redraw, MUIV_List_Redraw_Active);
  423.       }
  424.       break;
  425.   }
  426.   if (Signal)
  427.   { Wait(Signal);
  428.   }
  429.   return(1);
  430. }
  431. #endif    /*  AMIGA   */
  432.