Advanced Strategic Command
history.cpp
Go to the documentation of this file.
1 
5 // $Id: history.cpp,v 1.5 2009-04-18 13:48:37 mbickel Exp $
6 //
7 // $Log: not supported by cvs2svn $
8 // Revision 1.4 2004/06/23 19:36:21 mbickel
9 // Fixed: bug in detection of units that can fire on a moving unit
10 // Added: rename building
11 //
12 // Revision 1.3 2001/02/11 11:39:37 mbickel
13 // Some cleanup and documentation
14 //
15 // Revision 1.2 1999/11/16 03:41:50 tmwilson
16 // Added CVS keywords to most of the files.
17 // Started porting the code to Linux (ifdef'ing the DOS specific stuff)
18 // Wrote replacement routines for kbhit/getch for Linux
19 // Cleaned up parts of the code that gcc barfed on (char vs unsigned char)
20 // Added autoconf/automake capabilities
21 // Added files used by 'automake --gnu'
22 //
23 //
24 /*
25  This file is part of Advanced Strategic Command; http://www.asc-hq.de
26  Copyright (C) 1994-2010 Martin Bickel and Marc Schellenberger
27 
28  This program is free software; you can redistribute it and/or modify
29  it under the terms of the GNU General Public License as published by
30  the Free Software Foundation; either version 2 of the License, or
31  (at your option) any later version.
32 
33  This program is distributed in the hope that it will be useful,
34  but WITHOUT ANY WARRANTY; without even the implied warranty of
35  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36  GNU General Public License for more details.
37 
38  You should have received a copy of the GNU General Public License
39  along with this program; see the file COPYING. If not, write to the
40  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
41  Boston, MA 02111-1307 USA
42 */
43 
44 
45 /*
46  * Generated by TPTC - Translate Pascal to C
47  * Version 1.7 03/26/88 (C) 1988 S.H.Smith
48  */
49 //#include "tptcmac.h"
50 #include <tpascal.inc>
51 #include "typen.h"
52 #include "config.h"
53 #ifdef STDC_HEADERS
54 #include <stdlib.h>
55 #else
56 #ifdef HAVE_MALLOC_H
57 #include <malloc.h>
58 #else
59 char *malloc (int);
60 #endif
61 #endif
62 
63 
64 #define statc 0 /* StatisticCOlor */
65  #define hm 1.3 /* STatistic-Multiplikator Maxwert ist HM * grer als echter Maxwert */
66 
67 
68 
69  #define trounddata struct rounddata *
70  typedef struct rounddata {
71  word vehicle;
72  word buildings;
73  int energy;
75  int material;
77  int sprit;
78  int plus_fuel;
79  int research;
80  word devtechs;
81  } rounddata;
82  #undef trounddata
83  typedef struct rounddata *trounddata;
84  #define pround struct tround *
85  typedef struct tround {
86  int nr;
88  trounddata player[9];
89  } tround;
90  #undef pround
91  typedef struct tround *pround;
92 
93 pround rounds;
94  pround asr, ar;
95  pvehicle ae;
96  pbuilding ab;
97 
98 
99 void countunits(void)
100 { byte i, j;
101  boolean ex;
102 
103  ar = rounds;
104  do {
105  if (ar != NULL) ar = ar->next;
106  } while (!(ar == NULL));
107  ar = (tround *)malloc(sizeof(*ar));
108  ar->next = NULL;
109  for (i = 0; i <= 8; i++) ar->player[i] = NULL;
110  { void *with1 = &map;
111  ar->nr = turn;
112  for (i = 0; i <= 8; i++)
113  if (with1->player[i].existent == true) { void *with2 = &with1->player[i];
114  ar->player[i] = (rounddata *)malloc(sizeof(*ar->player[i]));
115  ar->player[i]->vehicle = 0;
116  ar->player[i]->buildings = 0;
117  ar->player[i]->material = 0;
118  ar->player[i]->plus_material = 0;
119  ar->player[i]->energy = 0;
120  ar->player[i]->plus_energy = 0;
121  ar->player[i]->sprit = 0;
122  ar->player[i]->plus_fuel = 0;
123  ar->player[i]->research = 0;
124  ar->player[i]->devtechs = 0;
125  if (firstvehicle != NULL) {
126  ae = firstvehicle;
127  do {
128  if (ae != NULL) {
129  inc(ar->player[i]->vehicle);
130  ae = ae->next;
131  }
132  } while (!(ae == NULL));
133  }
134  if (firstbuilding != NULL) {
135  ab = firstbuilding;
136  inc(ar->player[i]->buildings);
137  do {
138  if (ab != NULL) {
139  inc(ar->player[i]->buildings);
140  inc(ar->player[i]->material,ab->a.material);
141  inc(ar->player[i]->plus_material,ab->plus.a.material);
142  inc(ar->player[i]->energy,ab->a.energy);
143  inc(ar->player[i]->plus_energy,ab->plus_energy);
144  inc(ar->player[i]->sprit,ab->sprit);
145  inc(ar->player[i]->plus_fuel,ab->plus.a.fuel);
146  inc(ar->player[i]->research,ab->researchpoints);
147  j = 0;
148  do {
149  if (with2->research.developedtechnologies[j] != NULL) inc(j);
150  } while (!(with2->research.developedtechnologies[j] == NULL));
151  ar->player[i]->devtechs = j;
152  ab = ab->next;
153  }
154  } while (!(ab == NULL));
155  }
156  }
157 
158  }
159 
160  asr = rounds;
161  ex = false;
162  if (asr != NULL) {
163  do {
164  if (asr != NULL) {
165  if (asr->next == NULL) ex = true;
166  else asr = asr->next;
167  }
168  } while (!(ex == true));
169  asr->next = ar;
170  }
171  else displaymessage("History not started !","",0);
172 }
173 
174 
175 void starthistory(void)
176 { byte i;
177 
178  rounds = malloc(sizeof(*rounds));
179  for (i = 0; i <= 8; i++) rounds->player[i] = NULL;
180  rounds->nr = 0;
181  rounds->next = NULL;
182 }
183 
184 
185 void delhistory(void)
186 { byte i;
187 
188  while (rounds != NULL) {
189  ar = rounds;
190  for (i = 0; i <= 8; i++) if (ar->player[i] != NULL) {
191  dispose(&ar->player[i]);
192  ar->player[i] = NULL;
193  }
194  dispose(&ar);
195  ar = NULL;
196  rounds = rounds->next;
197  ar = rounds;
198  }
199 }
200 
201 typedef struct xy {
202  int x, y;
203  } xy;
204 
205  /* TShowHistory=(TDialogBox)
206  Action,ShowFlag,LId:Byte;
207  Max,Min,RoundNr:int;
208  Zplayer:ARRAY [0..8] OF Boolean;
209  PixS,MaxPix:XY;
210  Zoomx,ZoomY:Real;
211  procedure Init;
212  PROCEDURE Run; virtual;
213  PROCEDURE ButtonPressed(id:Byte); virtual;
214  FUNCTION GetData(P:PRound; player:Byte):int;
215  PROCEDURE GetInfo(VAR Mn,Mx,Round:int);
216  PROCEDURE PaintStat(Flag,id:Byte);
217  procedure Done;
218  END; */
219 
220 
222 {
223  word w, i;
224  #define kg 15
225 
226  inherited(); init();
227  action = 0;
228  title = "History";
229  sbld(x1,"%d",50);
230  xsize = 540;
231  y1 = 30;
232  ysize = 420;
233  maxpix.x = xsize - 60;
234  maxpix.y = ysize - 245;
235  pixs.x = 40 + x1;
236  pixs.y = ysize - 55 + y1;
237  lid = 0;
238 
239  w = (xsize - 20) / 4;
240  windowstyle = windowstyle ^ dlg_in3d;
241  showflag = 1;
242  for (i = 0; i <= 8; i++) if (actmap->player[i].existent == true) zplayer[i] = true;
243  else zplayer[i] = false;
244 
245  /* FOR i:=0 TO 3 DO BEGIN
246  AddButton('',30+i*60,50,30+KG+i*60,50+KG,3,1,i+2,True);
247  AddEingabe(i+2,Addr(Zplayer[i]),0,dblue);
248  END;
249 
250  FOR i:=4 TO 7 DO BEGIN
251  AddButton('',30+(i-4)*60,80,30+KG+(i-4)*60,80+KG,3,1,i+2,True);
252  AddEingabe(i+2,Addr(Zplayer[i]),0,dblue);
253  END;
254 
255  AddButton('',270,50,270+KG,50+KG,3,1,10,True);
256  AddEingabe(10,Addr(Zplayer[8]),0,dblue);
257 
258  AddKey(2,CT_1);
259  AddKey(3,CT_2);
260  AddKey(4,CT_3);
261  AddKey(5,CT_4);
262  AddKey(6,CT_5);
263  AddKey(7,CT_6);
264  AddKey(8,CT_7);
265  AddKey(9,CT_8);
266  AddKey(10,CT_9); */
267 
268  addbutton("Units",20,120,w,140,0,1,11,true);
269  addbutton("Buildings",20,155,w,175,0,1,12,true);
270 
271  addbutton("Energy",20 + w,120,2 * w,140,0,1,13,true);
272  addbutton("Energy +",20 + w,155,2 * w,175,0,1,14,true);
273 
274  addbutton("Material",20 + 2 * w,120,3 * w,140,0,1,15,true);
275  addbutton("Material +",20 + 2 * w,155,3 * w,175,0,1,16,true);
276 
277  addbutton("Fuel",20 + 3 * w,120,4 * w,140,0,1,17,true);
278  addbutton("Fuel +",20 + 3 * w,155,4 * w,175,0,1,28,true);
279 
280  addbutton("Research",330,45,xsize - 20,65,0,1,19,true);
281  addbutton("Developed Techs",330,80,xsize - 20,100,0,1,20,true);
282 
283  addbutton("~D~one",10,ysize - 30,xsize - 10,ysize - 10,0,1,24,true);
284 
285  buildgraphics();
286  rahmen(true,x1 + 20,y1 + 40,x1 + 300 + kg,y1 + 90 + kg);
287 
288  /* FOR i:=0 TO 3 DO BEGIN
289  NBar(x1+50+i*60,y1+50,x1+50+KG+i*60,y1+50+KG,20+i*8);
290  END;
291  FOR i:=4 TO 7 DO BEGIN
292  NBar(x1+50+(i-4)*60,y1+80,x1+50+KG+(i-4)*60,y1+80+KG,20+i*8);
293  END;
294  NBar(x1+290,y1+50,x1+290+KG,y1+50+KG,20+8*8); */
295 
296  paintstat(0,0);
297 
298  mousevisible(true);
299 }
300 
301 
302 void tshowhistoryrun(void)
303 {
304  do {
305  inherited(); run();
306  } while (!((taste == ct_esc) || (action == 1)));
307 }
308 
309 
311 {
312  /* IF (id>=2) AND (id<=10) THEN
313  IF Zplayer[id-2] THEN PaintStat(2,id-2)
314  ELSE PaintStat(1,id-2); */
315  if ((id >= 11) && (id <= 20) && (id != lid)) {
316  showflag = id - 10;
317  paintstat(0,0);
318  }
319  if (id == 24) action = 1;
320  lid = id;
321 }
322 
323 
324 void showplayerstat(byte sp,
325  boolean del)
326 {
327  lastp[sp].x = pixs.x;
328  lastp[sp].y = pixs.y;
329  if (del) setcolor(dblue);
330  else setcolor(20 + sp * 8);
331  ar = rounds;
332  while (ar != NULL) {
333  w = getdata(ar,sp);
334  if (w != -1) {
335  line(lastp[sp].x,lastp[sp].y,pixs.x + round(ar->nr * zoomx),pixs.y - round(w * zoomy));
336  lastp[sp].x = pixs.x + round(ar->nr * zoomx);
337  lastp[sp].y = pixs.y - round(w * zoomy);
338  }
339  ar = ar->next;
340  }
341 }
342 
343 
344 void tshowhistorypaintstat(byte flag,
345  byte id)
346 { word sp, b;
347  pround ar;
348  int w;
349  xy lastp[9];
350 
351 #define xstep 50 /* X-Beschriftungs-Abstand */
352  #define ystep 50 /* Y-Beschriftungs-Abstand */
353  #define linemx 5 /* X-Linien-Lnge */
354  #define linemy 5 /* Y-Linien-Lnge */
355 
356 
357 
358  if (flag == 0) {
359  getinfo(min,max,roundnr);
360  if (max == 1) max = round(max * 1.5);
361  else max = round(max * hm);
362  if (roundnr > 0) zoomx = maxpix.x / roundnr;
363  else zoomx = 9;
364  if (max > 0) zoomy = maxpix.y / max;
365  else zoomy = 1;
366  if ((zoomy == 0) || (zoomx == 0)) return;
367  nbar(pixs.x - 39,pixs.y - maxpix.y,pixs.x + maxpix.x,pixs.y + 10,dblue);
368  { void *with1 = &activefontsettings;
369  justify = centertext;
370  color = statc;
371  background = dblue;
372  return 25;
373  }
374 
375  nline(pixs.x - 5,pixs.y,pixs.x + maxpix.x + 5,pixs.y,statc);
376  nline(pixs.x,pixs.y - maxpix.y - 5,pixs.x,pixs.y + 5,statc);
377  b = 0;
378  while (b < round(maxpix.x / zoomx)) {
379  showtext2(strr(b),pixs.x + round(b * zoomx) - 10,pixs.y + 5);
380  nline(pixs.x + round(b * zoomx),pixs.y + linemy,pixs.x + round(b * zoomx),pixs.y - linemy,statc);
381  if (round(xstep / zoomx) == 0) inc(b,1);
382  else inc(b,round(xstep / zoomx));
383  }
384  { void *with1 = &activefontsettings;
385  justify = righttext;
386  }
387 
388  b = 0;
389  while (b < round(maxpix.y / zoomy)) {
390  showtext2(strr(b),pixs.x - 38,pixs.y - round(b * zoomy) - 5);
391  nline(pixs.x - linemx,pixs.y - round(b * zoomy),pixs.x + linemx,pixs.y - round(b * zoomy),statc);
392  if (round(ystep / zoomy) == 0) inc(b,1);
393  else inc(b,round(ystep / zoomy));
394  }
395  for (sp = 0; sp <= 8; sp++) lastp[sp].x = pixs.x;
396  for (sp = 0; sp <= 8; sp++) lastp[sp].y = pixs.y;
397  ar = rounds;
398  while (ar != NULL) {
399  for (sp = 8; sp >= 0; sp--)
400  if ((zplayer[sp]) && (ar->player[sp] != NULL)) {
401  w = getdata(ar,sp);
402  if (w != -1) {
403  setcolor(20 + sp * 8);
404  line(lastp[sp].x,lastp[sp].y,pixs.x + round(ar->nr * zoomx),pixs.y - round(w * zoomy));
405  lastp[sp].x = pixs.x + round(ar->nr * zoomx);
406  lastp[sp].y = pixs.y - round(w * zoomy);
407  }
408  }
409  ar = ar->next;
410  }
411  }
412  else if (flag == 1) {
413  showplayerstat(id,true);
414  for (sp = 0; sp <= 8; sp++)
415  if (zplayer[sp]) showplayerstat(sp,false);
416  nline(pixs.x - 5,pixs.y,pixs.x + maxpix.x + 5,pixs.y,statc);
417  nline(pixs.x,pixs.y - maxpix.y - 5,pixs.x,pixs.y + 5,statc);
418  }
419  else showplayerstat(id,false);
420 }
421 
422 
423 long * tshowhistorygetdata(struct * p,
424  int * player)
425 {
426  getdata = -1;
427  if (p == NULL) return;
428  if (p->player[player] == NULL) return;
429  switch (showflag) {
430 
431  case 1: getdata = p->player[player]->vehicle;
432  break;
433 
434  case 2: getdata = p->player[player]->buildings;
435  break;
436 
437  case 3: getdata = p->player[player]->energy;
438  break;
439 
440  case 4: getdata = p->player[player]->plus.energy;
441  break;
442 
443  case 5: getdata = p->player[player]->material;
444  break;
445 
446  case 6: getdata = p->player[player]->plus.material;
447  break;
448 
449  case 7: getdata = p->player[player]->sprit;
450  break;
451 
452  case 8: getdata = p->player[player]->plus.fuel;
453  break;
454 
455  case 9: getdata = p->player[player]->research;
456  break;
457 
458  case 10: getdata = p->player[player]->devtechs;
459  break;
460  }
461 }
462 
463 
464 void tshowhistorygetinfo(long * mn,
465  long * mx,
466  long * round)
467 { pround p;
468  int getdat, player;
469 
470  mn = 200000000;
471  mx = 0;
472  round = -1;
473  if (rounds->next == NULL) return;
474  round = 0;
475  p = rounds;
476  while (p != NULL) {
477  for (player = 0; player <= 8; player++)
478  if (p->player[player] != NULL) {
479  switch (showflag) {
480 
481  case 1: getdat = p->player[player]->vehicle;
482  break;
483 
484  case 2: getdat = p->player[player]->buildings;
485  break;
486 
487  case 3: getdat = p->player[player]->energy;
488  break;
489 
490  case 4: getdat = p->player[player]->plus.energy;
491  break;
492 
493  case 5: getdat = p->player[player]->material;
494  break;
495 
496  case 6: getdat = p->player[player]->plus.material;
497  break;
498 
499  case 7: getdat = p->player[player]->sprit;
500  break;
501 
502  case 8: getdat = p->player[player]->plus.fuel;
503  break;
504 
505  case 9: getdat = p->player[player]->research;
506  break;
507 
508  case 10: getdat = p->player[player]->devtechs;
509  break;
510  }
511  if (getdat > mx) mx = getdat;
512  if (getdat < mn) mn = getdat;
513  }
514  p = p->next;
515  inc(round);
516  }
517 }
518 
519  /* procedure TShowHistoryDone;
520 BEGIN
521  inherited Done;
522 END; */
523 
524 
525  /* PROCEDURE ShowHistory;
526 VAR ShowHistory:TShowHistory;
527 BEGIN
528  ShowHistory.Init;
529  ShowHistory.Run;
530  ShowHistory.Done;
531 END; */
532 
533 
534 
tfontsettings activefontsettings
Definition: newfont.cpp:51
#define dblue
Definition: misc.h:33
#define centertext
Definition: newfont.h:185
#define xstep
int plus_energy
Definition: history.cpp:74
int x
Definition: history.cpp:202
int nr
Definition: history.cpp:86
int y
Definition: history.cpp:202
long * tshowhistorygetdata(struct *p, int *player)
Definition: history.cpp:423
void tshowhistorybuttonpressed(void)
Definition: history.cpp:310
#define trounddata
Definition: history.cpp:69
void tshowhistoryrun(void)
Definition: history.cpp:302
void delhistory(void)
Definition: history.cpp:185
word devtechs
Definition: history.cpp:80
void tshowhistorygetinfo(long *mn, long *mx, long *round)
Definition: history.cpp:464
word vehicle
Definition: history.cpp:71
#define kg
#define pround
Definition: history.cpp:84
word buildings
Definition: history.cpp:72
#define linemx
pbuilding ab
Definition: history.cpp:96
int material
Definition: history.cpp:75
pround rounds
Definition: history.cpp:93
trounddata player[9]
Definition: history.cpp:88
struct xy xy
int sprit
Definition: history.cpp:77
char * malloc(int)
void rahmen(bool invers, int x1, int y1, int x2, int y2)
paints a pseudo-3D rectangle on the screen.
Definition: basegfx.cpp:82
void countunits(void)
Definition: history.cpp:99
#define hm
Definition: history.cpp:65
void showplayerstat(byte sp, boolean del)
Definition: history.cpp:324
void displaymessage(const char *formatstring, int num,...)
displays a dialog box with a message
Definition: dlg_box.cpp:1849
#define ct_esc
Definition: keysymbols.h:43
#define statc
Definition: history.cpp:64
struct tround tround
struct rounddata rounddata
Player player[9]
Definition: gamemap.h:253
void starthistory(void)
Definition: history.cpp:175
void showtext2(const ASCString &text, int x, int y)
Definition: basegfx.cpp:1953
#define linemy
Definition: history.cpp:201
int plus_fuel
Definition: history.cpp:78
#define righttext
Definition: newfont.h:186
#define dlg_in3d
Definition: dlg_box.h:33
pvehicle ae
Definition: history.cpp:95
GameMap * actmap
Definition: spfst.cpp:64
const T & max(const T &a, const T &b, const T &c)
Definition: misc.h:97
const T & min(const T &a, const T &b, const T &c)
Definition: misc.h:80
pround next
Definition: history.cpp:87
pround asr
Definition: history.cpp:94
while(1)
Definition: scanner.cpp:721
void mousevisible(int an)
Definition: events.cpp:75
int research
Definition: history.cpp:79
void tshowhistoryinit(void)
Definition: history.cpp:221
pround ar
Definition: history.cpp:94
void tshowhistorypaintstat(byte flag, byte id)
Definition: history.cpp:344
int plus_material
Definition: history.cpp:76
int energy
Definition: history.cpp:73
#define ystep
void line(int x1, int y1, int x2, int y2, Uint8 actcol)
draws a simple line on the screen. Not very fast...
Definition: basegfx.cpp:181