Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

history.cpp

Go to the documentation of this file.
00001 
00005 //     $Id: history.cpp,v 1.4 2004-06-23 19:36:21 mbickel Exp $
00006 //
00007 //     $Log: history.cpp,v $
00008 //     Revision 1.4  2004-06-23 19:36:21  mbickel
00009 //      Fixed: bug in detection of units that can fire on a moving unit
00010 //      Added: rename building
00011 //
00012 //     Revision 1.3  2001/02/11 11:39:37  mbickel
00013 //      Some cleanup and documentation
00014 //
00015 //     Revision 1.2  1999/11/16 03:41:50  tmwilson
00016 //      Added CVS keywords to most of the files.
00017 //      Started porting the code to Linux (ifdef'ing the DOS specific stuff)
00018 //      Wrote replacement routines for kbhit/getch for Linux
00019 //      Cleaned up parts of the code that gcc barfed on (char vs unsigned char)
00020 //      Added autoconf/automake capabilities
00021 //      Added files used by 'automake --gnu'
00022 //
00023 //
00024 /*
00025     This file is part of Advanced Strategic Command; http://www.asc-hq.de
00026     Copyright (C) 1994-1999  Martin Bickel  and  Marc Schellenberger
00027 
00028     This program is free software; you can redistribute it and/or modify
00029     it under the terms of the GNU General Public License as published by
00030     the Free Software Foundation; either version 2 of the License, or
00031     (at your option) any later version.
00032 
00033     This program is distributed in the hope that it will be useful,
00034     but WITHOUT ANY WARRANTY; without even the implied warranty of
00035     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00036     GNU General Public License for more details.
00037 
00038     You should have received a copy of the GNU General Public License
00039     along with this program; see the file COPYING. If not, write to the 
00040     Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
00041     Boston, MA  02111-1307  USA
00042 */
00043 
00044 
00045 /*
00046  * Generated by TPTC - Translate Pascal to C
00047  *     Version 1.7 03/26/88   (C) 1988 S.H.Smith
00048  */
00049 //#include "tptcmac.h"
00050 #include <tpascal.inc>
00051 #include "typen.h"
00052 #include "config.h"
00053 #ifdef STDC_HEADERS
00054 #include <stdlib.h>
00055 #else
00056 #ifdef HAVE_MALLOC_H
00057 #include <malloc.h>
00058 #else
00059 char *malloc (int);
00060 #endif
00061 #endif
00062 
00063 
00064 #define statc 0    /* StatisticCOlor */ 
00065       #define hm   1.3    /* STatistic-Multiplikator Maxwert ist HM * grӇer als echter Maxwert */ 
00066 
00067 
00068 
00069      #define trounddata struct rounddata * 
00070      typedef struct rounddata { 
00071                   word         vehicle; 
00072                   word         buildings; 
00073                   int      energy; 
00074                   int      plus_energy; 
00075                   int      material; 
00076                   int      plus_material; 
00077                   int      sprit; 
00078                   int      plus_fuel; 
00079                   int      research; 
00080                   word         devtechs; 
00081                } rounddata;
00082                #undef trounddata
00083                typedef struct rounddata *trounddata; 
00084      #define pround struct tround * 
00085      typedef struct tround { 
00086                int      nr; 
00087                pround       next; 
00088                trounddata   player[9]; 
00089             } tround;
00090             #undef pround
00091             typedef struct tround *pround; 
00092 
00093 pround       rounds; 
00094     pround       asr, ar; 
00095     pvehicle     ae; 
00096     pbuilding    ab; 
00097 
00098 
00099 void         countunits(void)
00100 { byte         i, j; 
00101     boolean      ex; 
00102 
00103    ar = rounds; 
00104    do { 
00105       if (ar != NULL) ar = ar->next; 
00106    }  while (!(ar == NULL)); 
00107    ar = (tround *)malloc(sizeof(*ar));
00108    ar->next = NULL; 
00109    for (i = 0; i <= 8; i++) ar->player[i] = NULL; 
00110    { void *with1 = &map; 
00111       ar->nr = turn; 
00112       for (i = 0; i <= 8; i++) 
00113          if (with1->player[i].existent == true) { void *with2 = &with1->player[i]; 
00114             ar->player[i] = (rounddata *)malloc(sizeof(*ar->player[i]));
00115             ar->player[i]->vehicle = 0; 
00116             ar->player[i]->buildings = 0; 
00117             ar->player[i]->material = 0; 
00118             ar->player[i]->plus_material = 0; 
00119             ar->player[i]->energy = 0; 
00120             ar->player[i]->plus_energy = 0; 
00121             ar->player[i]->sprit = 0; 
00122             ar->player[i]->plus_fuel = 0; 
00123             ar->player[i]->research = 0; 
00124             ar->player[i]->devtechs = 0; 
00125             if (firstvehicle != NULL) { 
00126                ae = firstvehicle; 
00127                do { 
00128                   if (ae != NULL) { 
00129                      inc(ar->player[i]->vehicle); 
00130                      ae = ae->next; 
00131                   } 
00132                }  while (!(ae == NULL)); 
00133             } 
00134             if (firstbuilding != NULL) { 
00135                ab = firstbuilding; 
00136                inc(ar->player[i]->buildings); 
00137                do { 
00138                   if (ab != NULL) { 
00139                      inc(ar->player[i]->buildings); 
00140                      inc(ar->player[i]->material,ab->a.material); 
00141                      inc(ar->player[i]->plus_material,ab->plus.a.material); 
00142                      inc(ar->player[i]->energy,ab->a.energy); 
00143                      inc(ar->player[i]->plus_energy,ab->plus_energy); 
00144                      inc(ar->player[i]->sprit,ab->sprit); 
00145                      inc(ar->player[i]->plus_fuel,ab->plus.a.fuel); 
00146                      inc(ar->player[i]->research,ab->researchpoints); 
00147                      j = 0; 
00148                      do { 
00149                         if (with2->research.developedtechnologies[j] != NULL) inc(j); 
00150                      }  while (!(with2->research.developedtechnologies[j] == NULL)); 
00151                      ar->player[i]->devtechs = j; 
00152                      ab = ab->next; 
00153                   } 
00154                }  while (!(ab == NULL)); 
00155             } 
00156             } 
00157          
00158       } 
00159    
00160    asr = rounds; 
00161    ex = false; 
00162    if (asr != NULL) { 
00163       do { 
00164          if (asr != NULL) { 
00165             if (asr->next == NULL) ex = true; 
00166             else asr = asr->next; 
00167          } 
00168       }  while (!(ex == true)); 
00169       asr->next = ar; 
00170    } 
00171    else displaymessage("History not started !","",0); 
00172 } 
00173 
00174 
00175 void         starthistory(void)
00176 { byte         i; 
00177 
00178    rounds = malloc(sizeof(*rounds));
00179    for (i = 0; i <= 8; i++) rounds->player[i] = NULL; 
00180    rounds->nr = 0; 
00181    rounds->next = NULL; 
00182 } 
00183 
00184 
00185 void         delhistory(void)
00186 { byte         i; 
00187 
00188    while (rounds != NULL) { 
00189       ar = rounds; 
00190       for (i = 0; i <= 8; i++) if (ar->player[i] != NULL) { 
00191          dispose(&ar->player[i]); 
00192          ar->player[i] = NULL; 
00193       } 
00194       dispose(&ar); 
00195       ar = NULL; 
00196       rounds = rounds->next; 
00197       ar = rounds; 
00198    } 
00199 } 
00200 
00201 typedef struct xy { 
00202            int      x, y; 
00203         } xy; 
00204 
00205   /*         TShowHistory=(TDialogBox)
00206                         Action,ShowFlag,LId:Byte;
00207                         Max,Min,RoundNr:int;
00208                         Zplayer:ARRAY [0..8] OF Boolean;
00209                         PixS,MaxPix:XY;
00210                         Zoomx,ZoomY:Real;
00211                         procedure Init;
00212                         PROCEDURE Run; virtual;
00213                         PROCEDURE ButtonPressed(id:Byte); virtual;
00214                         FUNCTION GetData(P:PRound; player:Byte):int;
00215                         PROCEDURE GetInfo(VAR Mn,Mx,Round:int);
00216                         PROCEDURE PaintStat(Flag,id:Byte);
00217                         procedure Done;
00218                      END; */ 
00219 
00220 
00221 void         tshowhistoryinit(void)
00222 { 
00223   word         w, i; 
00224   #define kg   15  
00225 
00226    inherited(); init(); 
00227    action = 0; 
00228    title = "History"; 
00229    sbld(x1,"%d",50); 
00230    xsize = 540; 
00231    y1 = 30; 
00232    ysize = 420; 
00233    maxpix.x = xsize - 60; 
00234    maxpix.y = ysize - 245; 
00235    pixs.x = 40 + x1; 
00236    pixs.y = ysize - 55 + y1; 
00237    lid = 0; 
00238 
00239    w = (xsize - 20) / 4; 
00240    windowstyle = windowstyle ^ dlg_in3d; 
00241    showflag = 1; 
00242    for (i = 0; i <= 8; i++) if (actmap->player[i].existent == true) zplayer[i] = true; 
00243    else zplayer[i] = false; 
00244 
00245      /* FOR i:=0 TO 3 DO BEGIN
00246       AddButton('',30+i*60,50,30+KG+i*60,50+KG,3,1,i+2,True);
00247       AddEingabe(i+2,Addr(Zplayer[i]),0,dblue);
00248    END;
00249 
00250    FOR i:=4 TO 7 DO BEGIN
00251       AddButton('',30+(i-4)*60,80,30+KG+(i-4)*60,80+KG,3,1,i+2,True);
00252       AddEingabe(i+2,Addr(Zplayer[i]),0,dblue);
00253    END;
00254 
00255    AddButton('',270,50,270+KG,50+KG,3,1,10,True);
00256    AddEingabe(10,Addr(Zplayer[8]),0,dblue);
00257 
00258    AddKey(2,CT_1);
00259    AddKey(3,CT_2);
00260    AddKey(4,CT_3);
00261    AddKey(5,CT_4);
00262    AddKey(6,CT_5);
00263    AddKey(7,CT_6);
00264    AddKey(8,CT_7);
00265    AddKey(9,CT_8);
00266    AddKey(10,CT_9); */ 
00267 
00268    addbutton("Units",20,120,w,140,0,1,11,true); 
00269    addbutton("Buildings",20,155,w,175,0,1,12,true); 
00270 
00271    addbutton("Energy",20 + w,120,2 * w,140,0,1,13,true); 
00272    addbutton("Energy +",20 + w,155,2 * w,175,0,1,14,true); 
00273 
00274    addbutton("Material",20 + 2 * w,120,3 * w,140,0,1,15,true); 
00275    addbutton("Material +",20 + 2 * w,155,3 * w,175,0,1,16,true); 
00276 
00277    addbutton("Fuel",20 + 3 * w,120,4 * w,140,0,1,17,true); 
00278    addbutton("Fuel +",20 + 3 * w,155,4 * w,175,0,1,28,true); 
00279 
00280    addbutton("Research",330,45,xsize - 20,65,0,1,19,true); 
00281    addbutton("Developed Techs",330,80,xsize - 20,100,0,1,20,true); 
00282 
00283    addbutton("~D~one",10,ysize - 30,xsize - 10,ysize - 10,0,1,24,true); 
00284 
00285    buildgraphics(); 
00286    rahmen(true,x1 + 20,y1 + 40,x1 + 300 + kg,y1 + 90 + kg); 
00287 
00288      /* FOR i:=0 TO 3 DO BEGIN
00289       NBar(x1+50+i*60,y1+50,x1+50+KG+i*60,y1+50+KG,20+i*8);
00290    END;
00291    FOR i:=4 TO 7 DO BEGIN
00292       NBar(x1+50+(i-4)*60,y1+80,x1+50+KG+(i-4)*60,y1+80+KG,20+i*8);
00293    END;
00294    NBar(x1+290,y1+50,x1+290+KG,y1+50+KG,20+8*8); */ 
00295 
00296    paintstat(0,0); 
00297 
00298    mousevisible(true); 
00299 } 
00300 
00301 
00302 void         tshowhistoryrun(void)
00303 { 
00304    do { 
00305       inherited(); run(); 
00306    }  while (!((taste == ct_esc) || (action == 1))); 
00307 } 
00308 
00309 
00310 void         tshowhistorybuttonpressed(void)
00311 { 
00312      /* IF (id>=2) AND (id<=10) THEN
00313       IF Zplayer[id-2] THEN PaintStat(2,id-2)
00314       ELSE PaintStat(1,id-2); */ 
00315    if ((id >= 11) && (id <= 20) && (id != lid)) { 
00316       showflag = id - 10; 
00317       paintstat(0,0); 
00318    } 
00319    if (id == 24) action = 1; 
00320    lid = id; 
00321 } 
00322 
00323 
00324 void         showplayerstat(byte         sp,
00325                              boolean      del)
00326 { 
00327    lastp[sp].x = pixs.x; 
00328    lastp[sp].y = pixs.y; 
00329    if (del) setcolor(dblue); 
00330    else setcolor(20 + sp * 8); 
00331    ar = rounds; 
00332    while (ar != NULL) { 
00333       w = getdata(ar,sp); 
00334       if (w != -1) { 
00335          line(lastp[sp].x,lastp[sp].y,pixs.x + round(ar->nr * zoomx),pixs.y - round(w * zoomy)); 
00336          lastp[sp].x = pixs.x + round(ar->nr * zoomx); 
00337          lastp[sp].y = pixs.y - round(w * zoomy); 
00338       } 
00339       ar = ar->next; 
00340    } 
00341 } 
00342 
00343 
00344 void         tshowhistorypaintstat(byte         flag,
00345                                    byte         id)
00346 { word         sp, b; 
00347     pround       ar; 
00348     int      w; 
00349     xy           lastp[9]; 
00350 
00351 #define xstep 50    /* X-Beschriftungs-Abstand */ 
00352       #define ystep 50    /* Y-Beschriftungs-Abstand */ 
00353       #define linemx 5    /* X-Linien-L„nge */ 
00354       #define linemy 5    /* Y-Linien-L„nge */ 
00355 
00356 
00357 
00358    if (flag == 0) { 
00359       getinfo(min,max,roundnr); 
00360       if (max == 1) max = round(max * 1.5); 
00361       else max = round(max * hm); 
00362       if (roundnr > 0) zoomx = maxpix.x / roundnr; 
00363       else zoomx = 9; 
00364       if (max > 0) zoomy = maxpix.y / max; 
00365       else zoomy = 1; 
00366       if ((zoomy == 0) || (zoomx == 0)) return;
00367       nbar(pixs.x - 39,pixs.y - maxpix.y,pixs.x + maxpix.x,pixs.y + 10,dblue); 
00368       { void *with1 = &activefontsettings; 
00369          justify = centertext; 
00370          color = statc; 
00371          background = dblue; 
00372          return 25; 
00373          } 
00374       
00375       nline(pixs.x - 5,pixs.y,pixs.x + maxpix.x + 5,pixs.y,statc); 
00376       nline(pixs.x,pixs.y - maxpix.y - 5,pixs.x,pixs.y + 5,statc); 
00377       b = 0; 
00378       while (b < round(maxpix.x / zoomx)) { 
00379          showtext2(strr(b),pixs.x + round(b * zoomx) - 10,pixs.y + 5); 
00380          nline(pixs.x + round(b * zoomx),pixs.y + linemy,pixs.x + round(b * zoomx),pixs.y - linemy,statc); 
00381          if (round(xstep / zoomx) == 0) inc(b,1); 
00382          else inc(b,round(xstep / zoomx)); 
00383       } 
00384       { void *with1 = &activefontsettings; 
00385          justify = righttext; 
00386          } 
00387       
00388       b = 0; 
00389       while (b < round(maxpix.y / zoomy)) { 
00390          showtext2(strr(b),pixs.x - 38,pixs.y - round(b * zoomy) - 5); 
00391          nline(pixs.x - linemx,pixs.y - round(b * zoomy),pixs.x + linemx,pixs.y - round(b * zoomy),statc); 
00392          if (round(ystep / zoomy) == 0) inc(b,1); 
00393          else inc(b,round(ystep / zoomy)); 
00394       } 
00395       for (sp = 0; sp <= 8; sp++) lastp[sp].x = pixs.x; 
00396       for (sp = 0; sp <= 8; sp++) lastp[sp].y = pixs.y; 
00397       ar = rounds; 
00398       while (ar != NULL) { 
00399          for (sp = 8; sp >= 0; sp--) 
00400             if ((zplayer[sp]) && (ar->player[sp] != NULL)) { 
00401                w = getdata(ar,sp); 
00402                if (w != -1) { 
00403                   setcolor(20 + sp * 8); 
00404                   line(lastp[sp].x,lastp[sp].y,pixs.x + round(ar->nr * zoomx),pixs.y - round(w * zoomy)); 
00405                   lastp[sp].x = pixs.x + round(ar->nr * zoomx); 
00406                   lastp[sp].y = pixs.y - round(w * zoomy); 
00407                } 
00408             } 
00409          ar = ar->next; 
00410       } 
00411    } 
00412    else if (flag == 1) { 
00413       showplayerstat(id,true); 
00414       for (sp = 0; sp <= 8; sp++) 
00415          if (zplayer[sp]) showplayerstat(sp,false); 
00416       nline(pixs.x - 5,pixs.y,pixs.x + maxpix.x + 5,pixs.y,statc); 
00417       nline(pixs.x,pixs.y - maxpix.y - 5,pixs.x,pixs.y + 5,statc); 
00418    } 
00419    else showplayerstat(id,false); 
00420 } 
00421 
00422 
00423 long *       tshowhistorygetdata(struct *     p,
00424                                  int *        player)
00425 { 
00426    getdata = -1; 
00427    if (p == NULL) return;
00428    if (p->player[player] == NULL) return;
00429    switch (showflag) {
00430       
00431       case 1:   getdata = p->player[player]->vehicle; 
00432       break; 
00433       
00434       case 2:   getdata = p->player[player]->buildings; 
00435       break; 
00436       
00437       case 3:   getdata = p->player[player]->energy; 
00438       break; 
00439       
00440       case 4:   getdata = p->player[player]->plus.energy; 
00441       break; 
00442       
00443       case 5:   getdata = p->player[player]->material; 
00444       break; 
00445       
00446       case 6:   getdata = p->player[player]->plus.material; 
00447       break; 
00448       
00449       case 7:   getdata = p->player[player]->sprit; 
00450       break; 
00451       
00452       case 8:   getdata = p->player[player]->plus.fuel; 
00453       break; 
00454       
00455       case 9:   getdata = p->player[player]->research; 
00456       break; 
00457       
00458       case 10:   getdata = p->player[player]->devtechs; 
00459    break; 
00460    } 
00461 } 
00462 
00463 
00464 void         tshowhistorygetinfo(long *       mn,
00465                                  long *       mx,
00466                                  long *       round)
00467 { pround       p; 
00468     int      getdat, player; 
00469 
00470    mn = 200000000; 
00471    mx = 0; 
00472    round = -1; 
00473    if (rounds->next == NULL) return;
00474    round = 0; 
00475    p = rounds; 
00476    while (p != NULL) { 
00477       for (player = 0; player <= 8; player++) 
00478          if (p->player[player] != NULL) { 
00479             switch (showflag) {
00480                
00481                case 1:   getdat = p->player[player]->vehicle; 
00482                break; 
00483                
00484                case 2:   getdat = p->player[player]->buildings; 
00485                break; 
00486                
00487                case 3:   getdat = p->player[player]->energy; 
00488                break; 
00489                
00490                case 4:   getdat = p->player[player]->plus.energy; 
00491                break; 
00492                
00493                case 5:   getdat = p->player[player]->material; 
00494                break; 
00495                
00496                case 6:   getdat = p->player[player]->plus.material; 
00497                break; 
00498                
00499                case 7:   getdat = p->player[player]->sprit; 
00500                break; 
00501                
00502                case 8:   getdat = p->player[player]->plus.fuel; 
00503                break; 
00504                
00505                case 9:   getdat = p->player[player]->research; 
00506                break; 
00507                
00508                case 10:   getdat = p->player[player]->devtechs; 
00509             break; 
00510             } 
00511             if (getdat > mx) mx = getdat; 
00512             if (getdat < mn) mn = getdat; 
00513          } 
00514       p = p->next; 
00515       inc(round); 
00516    } 
00517 } 
00518 
00519   /* procedure TShowHistoryDone;
00520 BEGIN
00521    inherited Done;
00522 END; */ 
00523 
00524 
00525   /* PROCEDURE ShowHistory;
00526 VAR ShowHistory:TShowHistory;
00527 BEGIN
00528    ShowHistory.Init;
00529    ShowHistory.Run;
00530    ShowHistory.Done;
00531 END; */ 
00532 
00533 
00534 

Generated on Tue Jun 24 01:27:44 2008 for Advanced Strategic Command by  doxygen 1.4.2