-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOGame_Types.pas
1538 lines (1376 loc) · 47.9 KB
/
OGame_Types.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit OGame_Types;
interface
uses
Sysutils, {$IFNDEF TEST}Languages,{$ENDIF} Math, LibXmlParser, LibXmlComps,
Classes, Dialogs, clipbrd, windows, CoordinatesRanges, cS_memstream;
type
TRessType = (rtMetal, rtKristal, rtDeuterium, rtEnergy);
TcSResource = Int64;
TSetRessources = array[TRessType] of TcSResource;
TLanguage = Word;
TScanGroup = (sg_Rohstoffe, sg_Flotten, sg_Verteidigung, sg_Gebaeude,
sg_Forschung);
const
{$IFDEF TEST} STR_M_Mond = 'M'; {$ENDIF}
{$IFDEF TEST} STR_P_Planet = 'P'; {$ENDIF}
max_Galaxy: word = 9;
max_Systems: word = 499;
TF_faktor_Fleet: Double = 0.3; //normal 30%
TF_faktor_Def: Double = 0.0; //normal 0%
{$IFDEF spacepioneers}
max_Planeten = 16;
{$ELSE}
max_Planeten = 15;
{$ENDIF}
maxraids24h: Integer = 5;
//Fileconsts: Scans
SF_Group_Count = 5;
fsc_0_Rohstoffe = 4;
{$IFDEF spacepioneers}
fsc_1_Flotten = 13; //SP: Gebäude
fsc_2_Verteidigung = 18; //SP: Flotte
fsc_3_Gebaeude = 10; //SP: Def
sb_Mine_array: array[rtMetal..rtDeuterium] of TScanData = ((1{Gebäude},0{MetallMine}),
(1{Gebäude},1{KristallMine}),
(1{Gebäude},2{TritMine}));
fsc_4_Forschung = 22;
{$ELSE}
// Flotten
fsc_1_Flotten = 14;
fleet_group = sg_Flotten;
sb_SolSat = 10;
// Verteidigung
fsc_2_Verteidigung = 10;
def_group = sg_Verteidigung;
fsc_3_Gebaeude = 18;
sb_Abfangraketen = 8;
sb_InterplanetarRaketen = 9;
//sb_Terraformer: TScanData = (3{Gebäude},12{Mondbasis});
sb_Metall = 0;
sb_Kristall = 1;
sb_Deuterium = 2;
sb_Energie = 3;
sb_Mondbasis = 15{Mondbasis};
sb_Sensorpalanx = 16{Sensorpalax};
sb_Ress_array: array[TRessType] of Integer = ((0{Metall}),
(1{Kristall}),
(2{Deuterium}),
(3{Energy}));
sb_Mine_array: array[rtMetal..rtDeuterium] of Integer = ((0{MetrallMine}),
(1{KristallMine}),
(2{DeutMine}));
sb_Speicher_array: array[rtMetal..rtDeuterium] of Integer = ((8{Metallspeicher}),
(9{Kristallspeicher}),
(10{Deuteriumtank}));
sb_SolKW = 3; //Solarkraftwerk
sb_FusionsKW = 4{FKW};
//Forschungen
fsc_4_Forschung = 16;
sb_Waffentechnik = 2;
sb_Schildtechnik = 3;
sb_Raumschiffpanzerung = 4;
sb_Energietechnik = 5;
sb_Intergal_ForschNetz = 13{Intergal.Forsch.Netz};
sb_Expeditionstechnik = 14{Expeditionstechnik};
sb_Gravitonforschung = 15{Gravitonforschung};
{$ENDIF}
ScanFileCounts: array[TScanGroup] of integer =
(fsc_0_Rohstoffe,fsc_1_Flotten,fsc_2_Verteidigung,fsc_3_Gebaeude,fsc_4_Forschung);
//------------------------------------------------------------------------
sys_playerstat_inactive = 0;
sys_playerstat_locked = 1;
sys_playerstat_longinactive = 2;
sys_playerstat_urlaub = 3;
sys_playerstat_noob = 4;
sys_playerstat_hard = 5;
type
TNameID = Int64;
TPlayerName = String[25]; //vermutlich 20
TAllyName = String[10]; //vermutlich 8
TPlanetName = String[25]; //eigentlich 20
TStati = 0..15; //16 Bit
TStatus = set of TStati;
PPlanetPosition = ^TPlanetPosition;
TPlanetPosition = record
P : array[0..2] of Word;
Mond : Boolean;
end;
TAbsPlanetNr = Cardinal;
PSystemPlanet = ^TSystemPlanet;
TSystemPlanet = record
Player: TPlayerName;
PlayerId: TNameID;
PlanetName: TPlanetName;
Ally: TAllyName;
AllyId: TNameID;
Status: TStatus;
MondSize: Word;
MondTemp: SmallInt;
TF: array[0..1] of Cardinal;
Activity: Integer; {Time in Seconds (min*60) befor Time_u, -15 -> (*) within last 15min, 0 -> activity > 60 minutes}
end;
PSystemCopy = ^TSystemCopy;
TSystemCopy = record
Time_u : Int64; //Unix
System : TPlanetPosition; //nur 0,1 wird dann verwendet!
Planeten : Array[1..max_Planeten] of TSystemPlanet;
Creator: TPlayerName;
end;
TSystemPosition = Array[0..1] of Word;
TSolSysPosition = TSystemPosition;
TScanHead = record
Planet: TPlanetName;
Position: TPlanetPosition;
Time_u: Int64; //Unix
Spieler: TPlayerName;
SpielerId: TNameID;
Spionageabwehr: integer;
Creator: TPlayerName;
{geraidet: Boolean;
von: TPlayerName;}
Activity: Integer; {Time in Seconds (min*60) befor Time_u, -1 -> no info, 0 -> activity > 60 minutes}
end;
TInfoArray = array of integer;
TScanBericht = class
private
fReadOnly: Boolean;
function getElement(sg: TScanGroup; index: integer): Int64;
procedure setElement(sg: TScanGroup; index: integer;
const Value: Int64);
public
Head : TScanHead;
resources: array[0..fsc_0_Rohstoffe-1] of TcSResource;
fleets : array[0..fsc_1_Flotten-1] of Integer;
defence : array[0..fsc_2_Verteidigung-1] of Integer;
buildings: array[0..fsc_3_Gebaeude-1] of ShortInt;
research : array[0..fsc_4_Forschung-1] of ShortInt;
property Bericht[sg: TScanGroup; index: integer]: Int64 read getElement write setElement;
property isReadOnly: Boolean read fReadOnly;
procedure lock;
procedure unlock;
class function Count(sg: TScanGroup): Integer;
constructor Create;
destructor Destroy; override;
function copy(): TScanBericht;
procedure copyFrom(scan: TScanBericht);
procedure clear();
procedure serialize(stream: TAbstractFixedMemoryStream);
procedure deserialize(stream: TAbstractFixedMemoryStream);
function serialize_size(): cardinal;
end;
TReadReport = class(TScanBericht)
public
AskMoon: Boolean;
end;
TReadReportList = class
private
flist: TList;
function getReport(index: integer): TReadReport;
public
property reports[index: integer]: TReadReport read getReport; default;
function push_back(scan: TReadReport): integer;
function Count: integer;
procedure clear;
constructor Create;
destructor Destroy; override;
end;
TRaidAuftrag = record
Start, Ziel: TPlanetPosition;
Zeit: TDateTime;
end;
TReportTime = record
Time_u: Int64;
ID: Integer;
end;
TReportTimeList = array of TReportTime;
TPlanetScanListSortType = (pslst_Nummer, pslst_Alter);
TStatType = (st_Player, st_Fleet, st_Ally);
TStatPlayer = record
Name: TPlayerName;
NameId: TNameID;
Punkte: Cardinal;
case TStatType of
st_Player: (Ally: TAllyName); //nur für spielerstats! bei allystats wird der allyname in den Spielernamen geschrieben!
st_Ally: (Mitglieder: Word);
end;
TStatNameType = (sntPlayer, sntAlliance);
TStatPointType = (sptPoints, sptFleet, sptResearch);
TStatTypeEx = record
NameType: TStatNameType;
PointType: TStatPointType;
end;
PStat = ^TStat;
TStat = record
first: Word;
count: byte;
Stats: array[0..99] of TStatPlayer;
Time_u: Int64;
end;
TredHoursTypes = (rh_Scans, rh_Systems, rh_Stats, rh_Points);
TredHours = array[TredHoursTypes] of Integer;
TResources = array[0..2] of TcSResource;
TReadDataXMLScanner = class(TXmlScanner)
private
group: Integer;
PROCEDURE ScannerProcessTag(Sender : TObject; TagName : STRING; Attributes : TAttrList; Empty: Boolean);
PROCEDURE ScannerStartTag(Sender : TObject; TagName : STRING; Attributes : TAttrList);
PROCEDURE ScannerEmptyTag(Sender : TObject; TagName : STRING; Attributes : TAttrList);
PROCEDURE ScannerTagReady(Sender : TObject; TagName : STRING);
public
constructor Create(AOwner: TComponent); override;
end;
TFleetsInfoSourceType = (fist_none, fist_events, fist_phalanx);
TFleetsInfoSource = record
typ: TFleetsInfoSourceType;
count: integer;
planet: TPlanetPosition;
time: Int64;
end;
PFleetEventScan = ^TFleetEventScan;
TFleetEventScanType = (fes_none, fes_own, fes_phalanx, fes_manuel);
TFleetEventScan = record
scanplayer: TPlayerName;
scantype: TFleetEventScanType;
scantime_u: Int64;
end;
TFleetEventType = (
fet_none,
fet_deploy, //Stationieren
fet_transport, //Transportieren
fet_attack, //Angreifen
fet_espionage, //Spionage
fet_harvest, //Recyclen
fet_colony, //Kolonisieren
fet_expedition //Expedition
);
const
FleetEventTypeNames: array[TFleetEventType] of string = (
'none',
'deploy',
'transport',
'attack',
'espionage',
'harvest',
'colony',
'expedition'
);
FleetEventTypeTranslate_: array[TFleetEventType] of string = (
'none',
'Stationieren',
'Transport',
'Angriff',
'Spionage',
'Abbauen',
'Kolonisieren',
'Expedition'
);
type
TFleetEventFlag = (fef_return, fef_friendly, fef_neutral, fef_hostile);
TFleetEventFlags = set of TFleetEventFlag;
TFleetEventHead = record
unique_id: integer; //ID from ogame database
eventtype: TFleetEventType;
eventflags: TFleetEventFlags;
origin, target: TPlanetPosition;
arrival_time_u: Int64;
player: TPlayerName;
joined_id: integer; //set an id > 0 if Fleet belongs to a "Verbands-Angriff"
end;
PFleetEvent_ = ^TFleetEvent;
TFleetEvent = record
head: TFleetEventHead;
ress: TInfoArray;
ships: TInfoArray;
end;
{TFleetJob = (fj_transport, fj_attack, fj_spy, fj_recycle, fj_colonize);
TFleetHead = record
Auftrag: TFleetJob;
Ankunft: Int64;
Spieler: TPlayerName;
StartPlanet,
ZielPlanet: TPlanetPosition;
Metall,
Kristall,
Deuterium: Integer;
notified: Boolean;
end;
PFleet = ^TFleet;
TFleet = record
head: TFleetHead;
ships: TInfoArray;
end;}
TOGameOptions = class
public
constructor Create(XML_Data_File: string);
end;
TTrimCharSet = set of Char;
var
game_sites_OLD: array of String;
xspio_idents: array[TScanGroup] of array of String;
maxPlanetTemp: array[1..max_Planeten] of single;
maxPlanetTemp_redesign: array[1..max_Planeten] of single;
fleet_resources: array[0..fsc_1_Flotten-1] of Tresources;
def_resources: array[0..fsc_2_Verteidigung-1] of Tresources;
// Interplanetarraketen und Abfangraketen werden nicht ins TF gerechnet, da
// sie nie am Kampf teilnehmen! (wird aus der xml-datei gelesen)
// def_ignoreTF == true heist also -> nicht ins TF reinrechnen
def_ignoreFight: array[0..fsc_2_Verteidigung-1] of Boolean;
ot_tousandsseperator: string;
UpdateCheckUrl, QuickUpdateUrl: string;
FOGameRangeList: TCoordinatesRangeList;
// Uni6 BetaUni bzw. Redesign
OGame_IsBetaUni: Boolean;
function FleetEventTypeToStrEx_(flt: TFleetEvent): string;
function FleetEventTypeToStr_(fj: TFleetEventType): string;
function FleetEventTypeToNameStr(fj: TFleetEventType): string;
procedure DeleteEmptyChar(var s: string);
function ReadPosOrTime(const s: string; p: Integer; var Position: TPlanetPosition): integer;
function PositionToStr_(pos: TPlanetPosition): string;
function PositionToStrA(pos: TPlanetPosition): string;
function PositionToStrMond(Pos: TplanetPosition): string;
function PositionToStrMondPlanet(Pos: TplanetPosition): string;
function PositionToStrAMond(Pos: TPlanetPosition): string;
function ValidPosition(pos: TPlanetPosition): boolean; overload;
function ValidPosition(pos: TSystemPosition): boolean; overload;
function TrimStringChar(S: string; C: Char): String;
function CountdownTimeToStr(time: TDateTime): String;
function ReadInt(s: string; p: integer; tsep: Boolean = True): int64;
function ReadIntEx(s: string; p: integer; IgnoreChars: string = '';
TrimChars: TTrimCharSet = ['-',' ',#9{Tab},#10]): int64;
procedure SortPlanetScanList(var List: TReportTimeList;
Typ: TPlanetScanListSortType);
function GetMineEnergyConsumption(Scan: TScanbericht): Integer;
function calcPlanetTemp(solsatenergy: single): single;
function calcSolSatEnergy(Scan: TScanBericht): Integer;
function calcProduktionsFaktor(Scan: TScanBericht; out needed_energy: Integer): single;
function GetMineProduction_(const Scan: TScanBericht;
const SpeedFactor: Single;
const Mine: TRessType;
const prod_faktor: single;
const calcMaxTemp: single (* set NaN for no use*)): TcSResource;
function MineProduction(Stufe: Integer; Mine: TRessType;
prod_faktor: single; planetTempMax: single): TcSResource;
procedure Initialise(XML_Data_File: string);
function CalcTF(Scan: TScanBericht): Tresources;
function FusionsKWDeut(stufe: integer): integer;
function NextPlanet(var Pos: TPlanetPosition): Boolean;
function CompareSys(Sys1, Sys2: TSystemCopy;
ignoreTime: Boolean = False): string;
function CompareScans(Scan1, Scan2: TScanBericht): string;
function SamePlanet(const Pos1, Pos2: TPlanetPosition): Boolean;
function IntToStrKP(i: Int64; kpc: char = #0): String;
function PosBigger(pos1, pos2: TPlanetPosition): boolean;
function StrToPosition(S: string): TPlanetPosition;
function StrToPositionEx(S: string): TPlanetPosition;
function SameFleetEvent(Fleet1, Fleet2: TFleetEvent): Boolean;
function OGameRangeList: TCoordinatesRangeList;
function AbsPlanetNrToPlanetPosition(nr: TAbsPlanetNr): TPlanetPosition;
function PlanetPositionToAbsPlanetNr(pos: TPlanetPosition): TAbsPlanetNr;
function checkMoonScan(var Report: TScanBericht): Boolean;
function BufFleetSize: Integer;
function ReadBufFleet(Buffer: Pointer): TFleetEvent;
procedure WriteBufFleet(const Fleet: TFleetEvent; Buffer: Pointer);
function CalcScanRess_Now_(Scan: TScanBericht; const Mine: TRessType;
alter_h: single; production_per_h: TcSResource): TcSResource;
function GetStorageSize(scan: TScanBericht; resstype: TRessType): TcSResource;
function GetScanGrpCount(Scan: TScanBericht): integer;
function domainTolangindex(domain: string): integer;
implementation
function domainTolangindex(domain: string): integer;
var i: integer;
begin
Result := -1;
for i := 0 to length(game_sites_OLD) - 1 do
begin
if domain = game_sites_OLD[i] then
begin
Result := i;
break;
end;
end;
end;
function checkMoonScan(var Report: TScanBericht): Boolean;
begin
{Diese Funktion überprüft anhand der Gebäudedaten ob es sich um einen Mond
handeln kann/muss oder nicht.
Falls der Mond(ob ja oder nein) eindeutig feststellbar ist wird True
zurückgegeben, und der Mond-Wert im Scan auf True bzw. False gesetzt.
falls es nicht eindeutig ist wird False zurückgegeben und am Scan nichts
unternommen.}
Result := False;
If (Report.Bericht[sg_Gebaeude,sb_Mine_array[rtMetal]] > 0)or
(Report.Bericht[sg_Gebaeude,sb_Mine_array[rtKristal]] > 0)or
(Report.Bericht[sg_Gebaeude,sb_Mine_array[rtDeuterium]] > 0) then
begin
Result := True; //Sicher kein Mond!
Report.Head.Position.Mond := False;
end
else if (Report.Bericht[sg_Gebaeude,sb_Mondbasis] > 0) then
begin
Result := True; //Sicher ein Mond!
Report.Head.Position.Mond := True;
end
else if (Report.Bericht[sg_Verteidigung,sb_Abfangraketen] > 0) or
(Report.Bericht[sg_Verteidigung,sb_InterplanetarRaketen] > 0) then
begin
Result := True; //Sicher kein Mond!
Report.Head.Position.Mond := false;
end;
end;
function IntToStrKP(i: Int64; kpc: char = #0): String;
var restore: char;
begin
restore := ThousandSeparator;
if kpc <> #0 then
ThousandSeparator := kpc;
Result := FloatToStrF(i,ffNumber,60000000,0);
ThousandSeparator := restore;
end;
function SamePlanet(const Pos1, Pos2: TPlanetPosition): Boolean;
begin
Result := (Pos1.P[0] = Pos2.P[0])and
(Pos1.P[1] = Pos2.P[1])and
(Pos1.P[2] = Pos2.P[2])and
(Pos1.Mond = Pos2.Mond);
end;
PROCEDURE TReadDataXMLScanner.ScannerProcessTag(Sender : TObject; TagName : STRING; Attributes : TAttrList; Empty: Boolean);
var s: string;
i: integer;
begin
DecimalSeparator := '.';
if TagName = 'updatecheck' then
UpdateCheckUrl := Attributes.Value('url')
else
if TagName = 'quickupdate' then
QuickUpdateUrl := Attributes.Value('url')
else
if TagName = 'raids' then
maxraids24h := StrToIntDef(Attributes.Value('maxraids24h'),maxraids24h)
else
if TagName = 'game' then
begin
s := Attributes.Value('count');
if s <> '' then i := StrToInt(s) else i := 0;
SetLength(game_sites_OLD,i);
end
else
if TagName = 'site' then
begin
s := Attributes.Value('index');
if s <> '' then i := StrToInt(s) else i := 0;
if (length(game_sites_OLD) <= i) then
ShowMessage('game sites count in Data is wrong!')
else game_sites_OLD[i] := Attributes.Value('name');
end
else
if TagName = 'planets' then
begin
s := Attributes.Value('count');
if (s = '')or(StrToInt(s) <> max_Planeten) then
ShowMessage('planetcount in Data is wrong!');
end
else
if copy(TagName,1,6) = 'planet' then
begin
i := ReadInt(TagName,7);
s := Attributes.Value('maxtemp');
if (i >= 1)and(i <= max_Planeten)and(s <> '') then
maxPlanetTemp[i] := StrToFloat(s);
s := Attributes.Value('maxtemp_redesign');
if (i >= 1)and(i <= max_Planeten)and(s <> '') then
maxPlanetTemp_redesign[i] := StrToFloat(s);
end
else
if TagName = 'units' then
begin
s := Attributes.Value('groupcount');
if (s = '')or(StrToInt(s) <> SF_Group_Count) then
ShowMessage('groupcount in Data is wrong!');
end
else
if copy(TagName,1,5) = 'group' then
begin
i := ReadInt(TagName,6);
s := Attributes.Value('count');
if (i >= 0)and(i <= SF_Group_Count-1)and(s <> '') then
begin
if StrToInt(s) <> scanfilecounts[TScanGroup(i)] then ShowMessage('unitcount(' + IntToStr(i) + ') in Data is wrong!');
group := i;
SetLength(xspio_idents[TScanGroup(i)],scanfilecounts[TScanGroup(i)]+1);
xspio_idents[TScanGroup(i)][0] := Attributes.Value('xml');
end else group := -1;
end
else
if copy(TagName,1,4) = 'unit' then
begin
i := ReadInt(TagName,5);
if (group >= 0)and(i >= 0)and(i <= scanfilecounts[TScanGroup(group)]-1) then
begin
xspio_idents[TScanGroup(group)][i+1] := Attributes.Value('xml');
if (group = Integer(fleet_group)) then
begin
s := Attributes.Value('met');
if s = '' then s := '0';
fleet_resources[i][0] := StrToInt(s);
s := Attributes.Value('crys');
if s = '' then s := '0';
fleet_resources[i][1] := StrToInt(s);
s := Attributes.Value('deut');
if s = '' then s := '0';
fleet_resources[i][2] := StrToInt(s);
end;
if (group = Integer(def_group)) then
begin
s := Attributes.Value('met');
if s = '' then s := '0';
def_resources[i][0] := StrToInt(s);
s := Attributes.Value('crys');
if s = '' then s := '0';
def_resources[i][1] := StrToInt(s);
s := Attributes.Value('deut');
if s = '' then s := '0';
def_resources[i][2] := StrToInt(s);
def_ignoreFight[i] := Attributes.Value('ignoreFight') = '1';
end;
end;
end;
end;
PROCEDURE TReadDataXMLScanner.ScannerStartTag(Sender : TObject; TagName : STRING; Attributes : TAttrList);
begin
ScannerProcessTag(Sender,TagName,Attributes,False);
end;
PROCEDURE TReadDataXMLScanner.ScannerEmptyTag(Sender : TObject; TagName : STRING; Attributes : TAttrList);
begin
ScannerProcessTag(Sender,TagName,Attributes,True);
end;
PROCEDURE TReadDataXMLScanner.ScannerTagReady(Sender : TObject; TagName : STRING);
begin
//nix!
end;
constructor TReadDataXMLScanner.Create(AOwner: TComponent);
begin
inherited;
OnStartTag := ScannerStartTag;
OnEmptyTag := ScannerEmptyTag;
OnEndTag := ScannerTagReady;
group := -1;
end;
procedure Initialise(XML_Data_File: string);
var XMLScanner: TReadDataXMLScanner;
sg: TScanGroup;
begin
XMLScanner := TReadDataXMLScanner.Create(nil);
XMLScanner.Filename := XML_Data_File;
XMLScanner.Execute;
XMLScanner.Free;
for sg := low(sg) to high(sg) do
begin
if (Length(xspio_idents[sg]) <> ScanFileCounts[sg]+1) then
begin
ShowMessage('Error in datafile! xspio_idents[' + IntToStr(Integer(sg)) + ']');
SetLength(xspio_idents[sg],ScanFileCounts[sg]+1);
end;
end;
FOGameRangeList := TCoordinatesRangeList.Create;
OGame_IsBetaUni := False;
end;
function ReadIntEx(s: string; p: integer; IgnoreChars: string = '';
TrimChars: TTrimCharSet = ['-',' ',#9{Tab},#10]): int64;
var apos : integer;
val : string;
begin
apos := p;
val := '';
while (apos <= length(s))and(s[apos] in TrimChars) do
inc(apos);
while (apos <= length(s))and
( (s[apos] in ['0'..'9'])or(pos(s[apos],IgnoreChars) > 0) ) do
begin
if (s[apos] in ['0'..'9']) then
val := val + s[apos];
inc(apos);
end;
if val <> '' then
result := StrToInt64(val)
else
result := 0;
end;
function ReadInt(s: string; p: integer; tsep: Boolean = True): int64;
begin
if tsep then
Result := ReadIntEx(s,p,ot_tousandsseperator)
else Result := ReadIntEx(s,p);
end;
function CountdownTimeToStr(time: TDateTime): String;
var h,m,s: integer;
str: string;
begin
h := trunc(time*24);
time := time - (h/24);
m := trunc(time*24*60);
time := time - (m/(24*60));
s := trunc(time*24*60*60);
str := IntToStr(m);
while length(str) < 2 do
str := '0'+str;
Result := IntToStr(h) + ':' + str + ':';
str := IntToStr(s);
while length(str) < 2 do
str := '0'+str;
Result := Result + str;
end;
function BufFleetSize: Integer;
var Fleet: TFleetEvent;
begin
Fleet.head.unique_id := 0; //Damit Compiler nicht warnt!
Result := SizeOf(Fleet.head);
Result := Result + (ScanFileCounts[sg_Flotten] * sizeof(Integer))
+ (ScanFileCounts[sg_Rohstoffe] * sizeof(Integer));
end;
function ReadBufFleet(Buffer: Pointer): TFleetEvent;
var z: pointer;
j: integer;
begin
z := Buffer;
j := SizeOf(Result.head);
CopyMemory(@Result.head, z, j);
z := pointer(integer(z)+j);
SetLength(Result.ress, ScanFileCounts[sg_Rohstoffe]);
SetLength(Result.ships, ScanFileCounts[sg_Flotten]);
for j := 0 to ScanFileCounts[sg_Rohstoffe]-1 do
begin
Result.ress[j] := Integer(z^);
z := pointer(integer(z)+sizeof(Integer));
end;
for j := 0 to ScanFileCounts[sg_Flotten]-1 do
begin
Result.ships[j] := Integer(z^);
z := pointer(integer(z)+sizeof(Integer));
end;
end;
procedure WriteBufFleet(const Fleet: TFleetEvent; Buffer: Pointer);
var z: pointer;
j: integer;
begin
z := Buffer;
j := SizeOf(Fleet.head);
CopyMemory(z, @Fleet.head, j);
z := pointer(integer(z)+j);
if length(Fleet.ships) <> ScanFileCounts[sg_Flotten] then
raise Exception.Create('WriteBufFleet: shiplist with unexpected length');
for j := 0 to ScanFileCounts[sg_Rohstoffe]-1 do
begin
Integer(z^) := Fleet.ress[j];
z := pointer(integer(z)+sizeof(Integer));
end;
for j := 0 to ScanFileCounts[sg_Flotten]-1 do
begin
Integer(z^) := Fleet.ships[j];
z := pointer(integer(z)+sizeof(Integer));
end;
end;
procedure DeleteEmptyChar(var s: string);
begin
while (length(s) > 0)and(s[1] in [' ',#9,#13,#10]) do
delete(s,1,1);
while (length(s) > 0)and(s[length(s)] in [' ',#9,#13,#10]) do
delete(s,length(s),1);
end;
function PosBigger(pos1, pos2: TPlanetPosition): boolean;
begin
Result := (pos1.P[0] > Pos2.P[0])or
((pos1.P[0] = Pos2.P[0])and(pos1.P[1] > Pos2.P[1]))or
((pos1.P[0] = Pos2.P[0])and(pos1.P[1] = Pos2.P[1])and(pos1.P[2] > Pos2.P[2]))or
((pos1.P[0] = Pos2.P[0])and(pos1.P[1] = Pos2.P[1])and(pos1.P[2] = Pos2.P[2])and(pos1.Mond > pos2.Mond));
end;
// returns 0 when failed to extract koords!
function ReadPosOrTime(const s: string; p: Integer; var Position: TPlanetPosition): integer;
var val : string;
pos, i, l : integer;
begin
Result := 0;
pos := p;
val := '';
i := 0;
l := length(s);
while (pos <= l) and (s[pos] in ['0'..'9',':','-']) do
begin
if s[pos] in ['-',':'] then
begin
if val <> '' then
Position.P[i] := strtoint(val)
else
exit;
val := '';
inc(i);
end
else
val := val + s[pos];
inc(pos);
end;
if val <> '' then
Position.P[i] := strtoint(val)
else
exit;
Result := pos;
end;
function PositionToStr_(pos: TPlanetPosition): string;
var i : integer;
begin
Result := '';
for i := 0 to 2 do
begin
result := result + inttostr(pos.P[i]);
if i <> 2 then result := result + ':';
end;
end;
function PositionToStrA(pos: TPlanetPosition): string;
var i : integer;
s : string;
begin
Result := '';
for i := 0 to 2 do
begin
s := IntToStr(pos.P[i]);
if i = 1 then
while length(s) < 3 do
s := '0' + s;
if i = 2 then
while length(s) < 2 do
s := '0' + s;
result := result + s;
if i <> 2 then result := result + ':';
end;
end;
function PositionToStrMond(Pos: TplanetPosition): string;
begin
Result := PositionToStr_(pos);
if Pos.Mond then Result := Result + ' ' + STR_M_Mond;
end;
function PositionToStrMondPlanet(Pos: TplanetPosition): string;
begin
Result := PositionToStr_(pos);
if Pos.Mond then
Result := Result + ' ' + STR_M_Mond
else
Result := Result + ' ' + STR_P_Planet;
end;
function PositionToStrAMond(Pos: TPlanetPosition): string;
begin
Result := PositionToStrA(pos);
if Pos.Mond then Result := Result + ' ' + STR_M_Mond;
end;
function ValidPosition(pos: TPlanetPosition): boolean;
begin
Result := (pos.p[0] > 0)and(pos.p[0] <= max_Galaxy)and
(pos.p[1] > 0)and(pos.p[1] <= max_Systems)and
(pos.p[2] > 0)and(pos.p[2] <= max_Planeten);
end;
function ValidPosition(pos: TSystemPosition): boolean;
begin
Result := (pos[0] > 0)and(pos[0] <= max_Galaxy)and
(pos[1] > 0)and(pos[1] <= max_Systems);
end;
function TrimStringChar(S: string; C: Char): String;
begin
if Length(s) = 0 then
if s[1] = C then
delete(s,1,1);
if Length(s) = 0 then
if s[length(s)] = C then
s := Copy(s,1,length(s)-1);
Result := s;
end;
procedure SortPlanetScanList(var List: TReportTimeList;
Typ: TPlanetScanListSortType);
procedure QuickSortNR(var A: array of TReportTime; iLo, iHi: Integer); //geklaut aus threaddemo!
var
Lo, Hi, Mid: Integer;
T: TReportTime;
begin
Lo := iLo;
Hi := iHi;
Mid := A[(Lo + Hi) div 2].ID;
repeat
while A[Lo].ID < Mid do Inc(Lo);
while A[Hi].ID > Mid do Dec(Hi);
if Lo <= Hi then
begin
//Sleep(Time);
//VisualSwap(A[Lo], A[Hi], Lo, Hi);
T := A[Lo];
A[Lo] := A[Hi];
A[Hi] := T;
Inc(Lo);
Dec(Hi);
end;
until Lo > Hi;
if Hi > iLo then QuickSortNR(A, iLo, Hi);
if Lo < iHi then QuickSortNR(A, Lo, iHi);
end;
procedure QuickSortAlter(var A: array of TReportTime; iLo, iHi: Integer); //geklaut aus threaddemo!
var
Lo, Hi: Integer;
Mid: TDateTime;
T: TReportTime;
begin
Lo := iLo;
Hi := iHi;
Mid := A[(Lo + Hi) div 2].Time_u;
repeat
while A[Lo].Time_u < Mid do Inc(Lo);
while A[Hi].Time_u > Mid do Dec(Hi);
if Lo <= Hi then
begin
//Sleep(Time);
//VisualSwap(A[Lo], A[Hi], Lo, Hi);
T := A[Lo];
A[Lo] := A[Hi];
A[Hi] := T;
Inc(Lo);
Dec(Hi);
end;
until Lo > Hi;
if Hi > iLo then QuickSortAlter(A, iLo, Hi);
if Lo < iHi then QuickSortAlter(A, Lo, iHi);
end;
begin
case Typ of
pslst_Nummer: QuickSortNR(List, Low(List), High(List));
pslst_Alter: QuickSortAlter(List, Low(List), High(List));
end;
end;
function CalcScanRess_Now_(Scan: TScanBericht; const Mine: TRessType;
alter_h: single; production_per_h: TcSResource): TcSResource;
var max, ress: TcSResource;
begin
if (Mine > rtDeuterium) then
raise Exception.Create('function CalcScanProductionRess: wrong Mine parameter!');
max := GetStorageSize(Scan, Mine);
ress := Scan.Bericht[sg_Rohstoffe,sb_Ress_array[mine]];
if ress > max then //Wenn schon mehr als Speicherkapazitär erlaubt -> keine Produktion!
Result := ress
else
begin
Result := ress + trunc(alter_h * production_per_h);
//Wenn Produktion höher als Speicherkapazität erlaubt -> Voll, und nicht mehr!!
if Result > max then
Result := max;
end;
end;
function GetMineEnergyConsumption(Scan: TScanbericht): Integer;
var stufe: integer;
mine: TRessType;
const konst_a: array[rtMetal..rtDeuterium] of Integer = (10, 10, 20);
begin
//Wenn Gebäude nicht bekannt:
if Scan.Bericht[sg_Gebaeude, 0] < 0 then
begin
Result := -1;
Exit;
end;
// Ansonsten:
Result := 0;
for mine := rtMetal to rtDeuterium do
begin
stufe := Scan.Bericht[sg_Gebaeude,sb_Mine_array[mine]];
if stufe >= 0 then
Result := Result + Ceil( konst_a[mine]*stufe*IntPower(1.1, stufe) );
end;
end;
function calcPlanetTemp(solsatenergy: single): single;
begin
solsatenergy := solsatenergy + 0.5; // Aufgrund Abrundung bei Energieberechnung in OGame
// kann der "Echte" Wert zwischen
// Solsatenergy und (Solsatenergy+1) liegen
// -> Mittelwert ist meist genauer
if OGame_IsBetaUni then
Result := (solsatenergy * 6) - 140
else
Result := (solsatenergy - 20) * 4;
end;
function calcSolSatEnergy(Scan: TScanBericht): Integer;
var enrgy_SolKW, enrgy_FusionKW, gesammt: integer;
stufe_SolKW, stufe_FusionKW, anzahl_solsat: integer;
stufe_energytech: Integer;
begin
Result := -1;
gesammt := Scan.Bericht[sg_Rohstoffe,sb_Ress_array[rtEnergy]];
stufe_SolKW := Scan.Bericht[sg_Gebaeude,sb_SolKW];
if stufe_SolKW < 0 then Exit;
stufe_FusionKW := Scan.Bericht[sg_Gebaeude,sb_FusionsKW];
if stufe_FusionKW < 0 then Exit;
stufe_energytech := Scan.Bericht[sg_Forschung,sb_Energietechnik];
if stufe_energytech < 0 then Exit;
anzahl_solsat := Scan.Bericht[sg_Flotten,sb_SolSat];
if anzahl_solsat <= 0 then Exit;