00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
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
00065 #define hm 1.3
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 = ↦
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
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
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
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
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
00289
00290
00291
00292
00293
00294
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
00313
00314
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
00352 #define ystep 50
00353 #define linemx 5
00354 #define linemy 5
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
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534