/* Chaos: The Chess HAppening Organisation System V5.1a Copyright (C) 1993 Jochen Wiedmann This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. $RCSfile: Runde.c,v $ $Revision: 1.1 $ $Date: 1993/08/19 14:06:14 $ This file contains the functions to enter results. Computer: Amiga 1200 Compiler: Dice 2.07.54 (3.0) Author: Jochen Wiedmann Am Eisteich 9 72555 Metzingen Tel. 07123 / 14881 Internet: wiedmann@mailserv.zdv.uni-tuebingen.de */ #ifndef CHAOS_H #include "chaos.h" #endif #ifndef INTUITION_GADGETCLASS_H #include #endif #ifndef CLIB_ALIB_PROTOS_H #include #endif #ifndef __STDIO_H #include #endif /* Die Funktion FreeRunde() gibt das durch eine Spielliste belegte RAM wieder frei. */ void FreeRunde (struct List *rlist) { struct GameNode *gn; if (rlist != NULL) { while ((gn = (struct GameNode *) rlist->lh_Head)->gn_Node.ln_Succ != NULL) { RemHead (rlist); FREESTRUCT(gn); } FREESTRUCT(rlist); } } /* Die Funktion GameFormat schreibt das Ergebnis eines Spiels als Text in die GameNode-Struktur. */ void FormatGame(struct GameNode *gn, int formatislong) { static char *ErgShort[4] = { "_:_", "0:1", "½:½", "1:0" }; static char *ErgLong[4] = { " _ : _ ", " 0 : 1 ", "1/2:1/2", " 1 : 0 "}; if (gn->Flags & GMFLAGSF_FREILOS) { sprintf(gn->Text, " %s: %s", (TurnierModus & TNMODEF_SCHWEIZER_SYSTEM) ? GetChaosString(MSG_FREE_POINT_OUTPUT) : GetChaosString(MSG_FREE_GAME_OUTPUT2), gn->Weiss->Name); } else { sprintf(gn->Text, "%4d %-30s:%-30s %s %s", gn->BrettNr+1, gn->Weiss->Name, gn->Schwarz->Name, formatislong ? ErgLong[gn->Ergebnis+1] : ErgShort[gn->Ergebnis+1], (gn->Flags & GMFLAGSF_KAMPFLOS) ? (char *) GetChaosString(MSG_NO_FIGHT_OUTPUT) : " "); } } /* Die Funktion GetRunde() bildet eine Liste aller Spiele einer Runde. */ struct List *GetRunde(int Runde, int MitFreilosen, int format) { struct List *rlist; struct GameNode *gn, *gnhelp; struct Teilnehmer *t; struct Game *g; if ((rlist = ALLOCSTRUCT(List)) == NULL) { goto Error; } NewList(rlist); for (t = (struct Teilnehmer *) Teilnehmerliste.lh_Head; t->Tn_Node.ln_Succ != NULL; t = (struct Teilnehmer *) t->Tn_Node.ln_Succ) { t->Hilfszeiger = NULL; } for (t = (struct Teilnehmer *) Teilnehmerliste.lh_Head; t->Tn_Node.ln_Succ != NULL; t = (struct Teilnehmer *) t->Tn_Node.ln_Succ) { if (t->Hilfszeiger == NULL) { g = SpielAdresse(t, Runde); if ((g->Flags & GMFLAGSF_FREILOS) != 0) { if (!MitFreilosen || ((TurnierModus & TNMODEF_SCHWEIZER_SYSTEM) && g->Ergebnis == 0)) { continue; } } else if ((g->Flags & GMFLAGSF_WEISS) == 0) { continue; } if ((gn = ALLOCSTRUCT(GameNode)) == NULL) { goto Error; } gn->gn_Node.ln_Name = gn->Text; g = SpielAdresse(t, Runde); gn->Weiss = t; gn->Schwarz = g->Gegner; gn->Ergebnis = g->Ergebnis; gn->BrettNr = (g->Flags & GMFLAGSF_FREILOS) ? 0x7fff : g->BrettNr; gn->Flags = g->Flags; t->Hilfszeiger = t; if (g->Gegner != NULL) { g->Gegner->Hilfszeiger = t; } for (gnhelp = (struct GameNode *) rlist->lh_Head; gnhelp->gn_Node.ln_Succ != NULL; gnhelp = (struct GameNode *) gnhelp->gn_Node.ln_Succ) { if (gn->BrettNr < gnhelp->BrettNr) { break; } } Insert(rlist, (struct Node *) gn, (struct Node *) gnhelp->gn_Node.ln_Pred); FormatGame(gn, format); } } return (rlist); Error: MemoryError(); FreeRunde(rlist); return(NULL); } /* Die Funktion ErgebnisEingabe() wird von main() aus aufgerufen. */ static int NumGameSelected; static struct GameNode *GameSelected; static struct List *GameList; static void SetErgebniseingabeGadgets(int num) { struct GameNode *gn; int i; for (i = 0, gn = (struct GameNode *) GameList->lh_Head; i < num; i++) { if (gn->gn_Node.ln_Succ != NULL) { gn = (struct GameNode *) gn->gn_Node.ln_Succ; } } if (gn->gn_Node.ln_Succ == NULL) { GT_SetGadgetAttrs(ErgebniseingabeGadgets[GD_Ergebnis], ErgebniseingabeWnd, NULL, GA_Disabled, TRUE, TAG_DONE); GT_SetGadgetAttrs(ErgebniseingabeGadgets[GD_Kampflos], ErgebniseingabeWnd, NULL, GA_Disabled, TRUE, TAG_DONE); GT_SetGadgetAttrs(ErgebniseingabeGadgets[GD_Spielliste], ErgebniseingabeWnd, NULL, GTLV_Labels, ~0, TAG_DONE); } else { GT_SetGadgetAttrs(ErgebniseingabeGadgets[GD_Ergebnis], ErgebniseingabeWnd, NULL, GA_Disabled, FALSE, GTMX_Active, 2-gn->Ergebnis, TAG_DONE); GT_SetGadgetAttrs(ErgebniseingabeGadgets[GD_Kampflos], ErgebniseingabeWnd, NULL, GA_Disabled, FALSE, GTMX_Active, (gn->Flags&GMFLAGSF_KAMPFLOS) ? 1 : 0, TAG_DONE); GT_SetGadgetAttrs(ErgebniseingabeGadgets[GD_Spielliste], ErgebniseingabeWnd, NULL, GTLV_Labels, GameList, GTLV_Selected, num, #ifdef V39_INCLUDES GTLV_MakeVisible, num, #endif TAG_DONE); } NumGameSelected = num; GameSelected = gn; } void ErgebnisEingabe(int Runde) { struct List *rlist; struct GameNode *gn; struct Teilnehmer *t; struct Game *g; int running; char titel[80]; sprintf(titel, (char *) GetChaosString(MSG_ROUND_INPUT_TITLE), Runde); ErgebniseingabeWdt = (STRPTR) titel; if ((rlist = GetRunde(Runde, FALSE, FALSE)) == NULL) { return; } if(OpenErgebniseingabeWindow() != 0) { CloseErgebniseingabeWindow(); FreeRunde(rlist); return; } GameList = rlist; SetErgebniseingabeGadgets(0); for(;;) { WaitPort(ErgebniseingabeWnd->UserPort); if ((running = HandleErgebniseingabeIDCMP()) == FALSE) { CloseErgebniseingabeWindow(); FreeRunde(rlist); return; } else if(running == -1) { CloseErgebniseingabeWindow(); /* Eventuelle Ergebnisänderungen merken */ for(gn = (struct GameNode *) rlist->lh_Head; gn->gn_Node.ln_Succ != NULL; gn = (struct GameNode *) gn->gn_Node.ln_Succ) { t = gn->Weiss; g = SpielAdresse(t, Runde); if (g->Ergebnis != gn->Ergebnis || g->Flags != gn->Flags) { IsSaved = FALSE; } if (gn->Ergebnis == -1 && g->Ergebnis != -1) { NumFehlendeSpiele++; } else if (gn->Ergebnis != -1 && g->Ergebnis == -1) { NumFehlendeSpiele--; } if (g->Ergebnis != -1) { t->Punkte -= g->Ergebnis; } if (gn->Ergebnis != -1) { t->Punkte += gn->Ergebnis; } g->Ergebnis = gn->Ergebnis; g->Flags = gn->Flags; if((t = gn->Schwarz) != NULL) { g = SpielAdresse(t, Runde); if (g->Ergebnis != -1) { t->Punkte -= g->Ergebnis; } if (gn->Ergebnis == -1) { g->Ergebnis = -1; } else { g->Ergebnis = 2-gn->Ergebnis; t->Punkte += g->Ergebnis; } g->Flags = gn->Flags & ~GMFLAGSF_WEISS; } } FreeRunde(rlist); return; } } } int ErgebniseingabeCloseWindow( void ) { /* routine for "IDCMP_CLOSEWINDOW". */ return(FALSE); } int ErgebniseingabeRawKey( void ) { /* routine for "IDCMP_RAWKEY". */ if (ErgebniseingabeMsg.Qualifier == 0x8000) { switch (ErgebniseingabeMsg.Code) { case 0x44: /* Return-Taste */ if (ErgebniseingabeMsg.Qualifier & IEQUALIFIER_CONTROL) { return(-1); } break; case 0x45: /* Esc-Taste */ return(0); } } return(TRUE); } int Ok3Clicked( void ) { /* routine when gadget "Ok" is clicked. */ return(-1); } int Cancel3Clicked( void ) { /* routine when gadget "Cancel" is clicked. */ return(FALSE); } int ErgebnisClicked( void ) { /* routine when gadget "" is clicked. */ if (ErgebniseingabeMsg.Code == 3) { GameSelected->Ergebnis = -1; } else { GameSelected->Ergebnis = 2-ErgebniseingabeMsg.Code; } GT_SetGadgetAttrs(ErgebniseingabeGadgets[GD_Spielliste], ErgebniseingabeWnd, NULL, GTLV_Labels, ~0, TAG_DONE); FormatGame(GameSelected, FALSE); SetErgebniseingabeGadgets(NumGameSelected); if (GameSelected->gn_Node.ln_Succ->ln_Succ != NULL) { SetErgebniseingabeGadgets(NumGameSelected+1); } return(TRUE); } int KampflosClicked( void ) { /* routine when gadget "" is clicked. */ GameSelected->Flags &= ~GMFLAGSF_KAMPFLOS; if (ErgebniseingabeMsg.Code != 0) { GameSelected->Flags |= GMFLAGSF_KAMPFLOS; } GT_SetGadgetAttrs(ErgebniseingabeGadgets[GD_Spielliste], ErgebniseingabeWnd, NULL, GTLV_Labels, ~0, TAG_DONE); FormatGame(GameSelected, FALSE); SetErgebniseingabeGadgets(NumGameSelected); return(TRUE); } int SpiellisteClicked( void ) { int num = ErgebniseingabeMsg.Code; SetErgebniseingabeGadgets(num); return(TRUE); }