-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathaScriptFun.pas
15996 lines (13702 loc) · 492 KB
/
aScriptFun.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 aScriptFun;
interface
uses EC_Expression;
procedure ScriptFunInit(va:TVarArrayEC);
implementation
uses SysUtils,Classes,Math,
aMyFunction,Globals,GlobalsV,aItem,aConst,aGalaxy,aScript,aShip,aNormalShip,aPlayer,aRanger,aPlanet,aWarrior,aRuins,
aKling,aPirate,aTransport,aEFilm,GR_Main,EC_Str,EC_Struct,fEquipmentShop,ab_Hit,ab_Ship,Robot,
GI_MessageLoop,GI_GraphButton,GI_Label,GI_Image,GI_GI,GI_GAI,GI_GraphBuf,
EC_BlockPar,ThreadCalc,aSaveLoad,fPanelLoad,SE_Process,SE_Space,SE_Ship2,SE_GAIEffect,
SE_Ruins,SE_Planet,fStarMap,fShip2,fPanelMain, ab_ShipAI,ab_W,EC_Mem, aGalaxyEvent, aGalaxyStruct,
Achievements,GI_XviD,MMSystem,aTranclucator,GI_MessageBox,fCount2,fCount1,fTextBox,fListBox,aMissile,aAsteroid,fTalk,fCustom,
SE_Weapon,aEFilmEnd,aCalc,fGalaxy,GI_Edit,BreakMessageGIException;
procedure SF_GRun(av:array of TVarEC; code:TCodeEC);
begin
GScriptGlobalRun:=true;
end;
procedure SF_GCntRun(av:array of TVarEC; code:TCodeEC);
var
no:integer;
begin
if High(av)<>1 then raise Exception.Create('Error.Script SF_GCntRun');
no:=FindScriptTempl(av[1].VStr);
if no<0 then raise Exception.Create('Error.Script.NotFound SF_GCntRun');
av[0].VInt:=TScriptTemplUnit(GScriptTempl.Items[no]).FCntUse;
end;
procedure SF_GLastTurnRun(av:array of TVarEC; code:TCodeEC);
var
no:integer;
begin
if High(av)<1 then raise Exception.Create('Error.Script SF_GCntRun');
no:=FindScriptTempl(av[1].VStr);
if no<0 then raise Exception.Create('Error.Script.NotFound SF_GLastTurnRun');
if (High(av)>=2) and (TScriptTemplUnit(GScriptTempl.Items[no]).FCntUse<1) then begin
av[0].VInt:=av[2].VInt;
end else begin
av[0].VInt:=TScriptTemplUnit(GScriptTempl.Items[no]).FLastTurn;
end;
end;
procedure SF_GAllCntRun(av:array of TVarEC; code:TCodeEC);
var
cnt,zn,i:integer;
begin
if High(av)>=1 then begin
zn:=av[1].VInt;
cnt:=0;
for i:=0 to Galaxy.FScripts.Count-1 do begin
if TScript(Galaxy.FScripts.Items[i]).FClass=zn then begin
inc(cnt);
end;
end;
av[0].VInt:=cnt;
end else begin
av[0].VInt:=Galaxy.FScripts.Count;
end;
end;
procedure SF_IsScriptActive(av:array of TVarEC; code:TCodeEC);
var
no:integer;
begin
if High(av)<1 then raise Exception.Create('Error.Script IsScriptActive');
av[0].VInt:=0;
no:=FindScriptTempl(av[1].VStr);
if no>=0 then av[0].VInt:=ord(TScriptTemplUnit(GScriptTempl.Items[no]).FRunScript >=0 );
//IsScriptActive('MS_Begin');
end;
procedure SF_GetValueFromScript(av:array of TVarEC; code:TCodeEC);
var
no,cnt:integer;
scr:TScript;
v:TVarEC;
begin
cnt:=High(av);
if cnt<2 then raise Exception.Create('Error.Script GetValueFromScript');
if av[1].VStr='' then
begin
v:=GScriptFun.GetVarNE(av[2].VStr);
if v=nil then raise Exception.Create('Error.Script GetValueFromScript - var '+av[2].VStr+' not found');
end else begin
no:=FindScriptTempl(av[1].VStr);
if no<0 then exit;
no:=TScriptTemplUnit(GScriptTempl.Items[no]).FRunScript;
if no<0 then exit;
scr:=Galaxy.FScripts[no];
v:=scr.FCodeInit.LocalVar.GetVarNE(av[2].VStr);
if v=nil then v:=scr.FCodeNextTurn.LocalVar.GetVarNE(av[2].VStr);
if v=nil then v:=GScriptFun.GetVarNE(av[2].VStr);
if v=nil then raise Exception.Create('Error.Script GetValueFromScript - var '+av[2].VStr+' not found in script '+av[1].VStr);
end;
no:=2;
while (v.VType = vtArray) and (no<cnt) do
begin
inc(no);
if av[no].VType = vtStr then v:=v.VArray.GetVar(av[no].VStr)
else v:=v.VArray.Items[av[no].VInt];
end;
case v.VType of
vtInt: av[0].VInt:=v.VInt;
vtDW: av[0].VDW:=v.VDW;
vtFloat: av[0].VFloat:=v.VFloat;
vtStr: av[0].VStr:=v.VStr;
vtArray: av[0].VInt:=v.VArray.Count;
end;
//GetValueFromScript('MS_Begin','vSBId');
end;
procedure SF_RunFunctionFromScript(av:array of TVarEC; code:TCodeEC);
var
no,cnt,u:integer;
scr:TScript;
v:TVarEC;
name:WideString;
tcfun:TCodeEC;
begin
cnt:=High(av);
if cnt<2 then raise Exception.Create('Error.Script RunFunctionFromScript');
no:=FindScriptTempl(av[1].VStr);
if no<0 then exit;
no:=TScriptTemplUnit(GScriptTempl.Items[no]).FRunScript;
if no<0 then exit;
scr:=Galaxy.FScripts[no];
name:='g_'+av[2].VStr;
v:=scr.FCodeInit.LocalVar.GetVarNE(name);
if v=nil then v:=scr.FCodeNextTurn.LocalVar.GetVarNE(name);
if (v=nil) or (v.VType <> vtFun) then raise Exception.Create('Error.Script RunFunctionFromScript - function '+name+' not found in script '+av[1].VStr);
//if v.VFun.LocalVar.GetVar('funBaseVarCount').VInt<(High(av)-2) then raise ExceptionExpressionEC.Create('Count var error. fun:'+v.Name);
tcfun:=TCodeEC.Create;
//tcfun.FParent:=v.VFun;
tcfun.CopyFromFast(v.VFun);
for u:=3 to cnt do
begin
if tcfun.LocalVar.Items[u-3].RealVType=vtRef then tcfun.LocalVar.Items[u-3].VRef:=av[u]
else tcfun.LocalVar.Items[u-3].Assume(av[u]);
end;
try
tcfun.LocalVar.GetVar('result').VRef:=av[0];
tcfun.Run(GScriptCP);
except
on E:EBreakMessageGI do begin tcfun.Free; Raise; end;
on E:Exception do
begin
raise ExceptionExpressionEC.Create('Error in function '+v.Name+' ('+ E.ClassName + ' '+E.Message+')');
end;
end;
tcfun.Free;
end;
procedure SF_GetVariableName(av:array of TVarEC; code:TCodeEC);
begin
if High(av)<1 then raise Exception.Create('Error.Script GetVariableName');
av[0].VStr:=av[1].Name;
end;
procedure SF_GetVariableType(av:array of TVarEC; code:TCodeEC);
begin
if High(av)<1 then raise Exception.Create('Error.Script GetVariableType');
av[0].VInt:=ord(av[1].VType);
end;
procedure SF_AddPlanetNews(av:array of TVarEC; code:TCodeEC);
begin
if High(av)<1 then raise Exception.Create('Error.Script AddPlanetNews');
if High(av)>1 then Galaxy.AddPlanetNews(TDifferentSituationInPlanet(av[2].VInt),av[1].VStr)
else Galaxy.AddPlanetNews(dsGalaxyNews,av[1].VStr);
end;
procedure SF_AddJournalRecord(av:array of TVarEC; code:TCodeEC);
var
jrn: TJournalRecord;
i,recTurn:integer;
begin
if High(av)<1 then raise Exception.Create('Error.Script AddJournalRecord');
if High(av)=1 then
begin
Player.AddJournalRecord(av[1].VStr);
exit;
end;
recTurn:=av[2].VInt;
jrn := TJournalRecord.Create;
jrn.FText := av[1].VStr;
jrn.FTurn := recTurn;
if (Player.FJournals.Count<=0) or (TJournalRecord(Player.FJournals[Player.FJournals.Count-1]).FTurn<=recTurn) then
begin
Player.FJournals.Add(jrn);
exit;
end;
for i:=Player.FJournals.Count-2 downto 0 do
if TJournalRecord(Player.FJournals[i]).FTurn<=recTurn then
begin
Player.FJournals.Insert(i+1,jrn);
exit;
end;
Player.FJournals.Insert(0,jrn);
end;
procedure SF_AutoBattle(av:array of TVarEC; code:TCodeEC);
begin
if High(av)<>1 then raise Exception.Create('Error.Script AutoBattle');
AutoBattleShip:=TShip(av[1].VDW);
end;
procedure SF_GetOwner(av:array of TVarEC; code:TCodeEC);
var
ship:TShip;
owner:integer;
begin
if High(av)<>1 then raise Exception.Create('Error.Script SF_GetOwner');
ship:=TShip(av[1].VDW);
owner:=integer(ship.FOwner);
av[0].VInt:=owner;
end;
procedure SF_GiveReward(av:array of TVarEC; code:TCodeEC);
var
ship:TShip;
owner:TOwner;
reward:TReward;
number:integer;
breward:PByte;
begin
if(High(av) < 3) then raise Exception.Create('Error.Script SF_GiveReward');
ship:=TShip(av[1].VDW);
owner:=TOwner(av[2].Vint);
reward:=TReward(av[3].Vint);//ForLiberationSystem, ForAccomplishment, ForSecretMission, ForCowardice, ForPerfidy, ForPlanetBattle
number:=(ship as TNormalShip).RewardNumber(owner,[reward]);
if(number = 255) then EError('Error RewardNumber=255');
ship.AddReward(number);
av[0].VInt:=number;
end;
procedure SF_GiveRewardByNom(av:array of TVarEC; code:TCodeEC);
var
ship:TShip;
begin
if(High(av) < 2) then raise Exception.Create('Error.Script SF_GiveRewardByNom');
ship:=TShip(av[1].VDW);
ship.AddReward(av[2].VInt);
end;
procedure SF_CountReward(av:array of TVarEC; code:TCodeEC);
var
ship:TShip;
reward:TReward;
i,cnt:integer;
begin
if(High(av) < 1) then raise Exception.Create('Error.Script SF_CountReward');
ship:=TShip(av[1].VDW);
if(High(av) = 1) then
begin
if (ship.FRewards=nil) or (ship.FRewards.Count=0) then
begin
av[0].VStr:='';
exit;
end;
av[0].VStr:=IntToStrEC(integer(ship.FRewards.Items[0]));
for i:=1 to ship.FRewards.Count-1 do
av[0].VStr:=av[0].VStr+','+IntToStrEC(integer(ship.FRewards.Items[i]));
exit;
end;
reward:=TReward(av[2].Vint);//ForLiberationSystem, ForAccomplishment, ForSecretMission, ForCowardice, ForPerfidy, ForPlanetBattle
if ship.FRewards=nil then
begin
av[0].VInt:=0;
exit;
end;
cnt:=0;
for i:=0 to ship.FRewards.Count-1 do
if SysToReward(CT('Reward.' + IntToStr(integer(ship.FRewards.Items[i])) + '.Type'))=reward then inc(cnt);
av[0].VInt:=cnt;
end;
procedure SF_CountRewardByNom(av:array of TVarEC; code:TCodeEC);
var
ship:TShip;
i,cnt,no:integer;
begin
if(High(av) < 2) then raise Exception.Create('Error.Script SF_CountRewardByNom');
ship:=TShip(av[1].VDW);
no:=av[2].VInt;
if ship.FRewards=nil then
begin
av[0].VInt:=0;
exit;
end;
cnt:=0;
for i:=0 to ship.FRewards.Count-1 do
if integer(ship.FRewards.Items[i])=no then inc(cnt);
av[0].VInt:=cnt;
end;
procedure SF_DeleteRewardByNom(av:array of TVarEC; code:TCodeEC);
var
ship:TShip;
i,cnt,no:integer;
begin
if(High(av) < 2) then raise Exception.Create('Error.Script SF_DeleteRewardByNom');
ship:=TShip(av[1].VDW);
no:=av[2].VInt;
if High(av) > 2 then cnt:=av[3].VInt else cnt:=1;
av[0].VInt:=0;
if ship.FRewards=nil then exit;
for i:=ship.FRewards.Count-1 downto 0 do
if (integer(ship.FRewards.Items[i])=no) or (no=-1) then
begin
ship.FRewards.Delete(i);
av[0].VInt:=av[0].VInt+1;
if av[0].VInt >= cnt then exit;
end;
end;
procedure SF_ShipPicksItem(av:array of TVarEC; code:TCodeEC);
var
ship:TShip;
item:TItem;
i,cnt,no:integer;
begin
if High(av) < 2 then raise Exception.Create('Error.Script SF_ShipPicksItem');
ship:=TShip(av[1].VDW);
item:=TItem(av[2].VDW);
if High(av)=2 then
begin
if ship.TakeItems_Test(item) then av[0].VInt:=1
else if ship.RecentlyDroppedItem(item) then av[0].VInt:=-1
else av[0].VInt:=0;
exit;
end;
if av[3].VInt>0 then
begin
ship.TakeItems_Add(item);
if ship.RecentlyDroppedItem(item) then
ship.FRecentlyDroppedItems.Delete(ship.FRecentlyDroppedItems.IndexOf(item));
end
else if av[3].VInt<0 then
begin
ship.TakeItems_Del(item);
ship.RecentlyDroppedItems_Add(item);
end
else
begin
ship.TakeItems_Del(item);
if ship.RecentlyDroppedItem(item) then
ship.FRecentlyDroppedItems.Delete(ship.FRecentlyDroppedItems.IndexOf(item));
end;
end;
procedure SF_DropItem(av:array of TVarEC; code:TCodeEC);
label done;
var
ship:TShip;
eq:TEquipment;
itemtype:TItemType;
i,nodropflag:integer;
found:boolean;
ExlplotableState:boolean;
sitem:TScriptItem;
begin
found:=false;
if High(av)<2 then raise Exception.Create('Error.Script SF_DropItem');
ship:=TShip(av[1].VDW);
if (av[2].VType = vtDW) and (av[2].VDW > 65536) then
begin
eq:=TEquipment(av[2].VDW);
if High(av)>=3 then
begin
sitem:=TScriptItem(av[3].VDW);
if sitem.FItem<>nil then sitem.FItem.FScriptItem:=nil;
sitem.FItem:=eq;
eq.FScriptItem:=sitem;
end;
nodropflag:=eq.FFlag_NoDrop;
eq.FFlag_NoDrop:=0;
ship.DropEx(eq);
if ship.FCurStar.FItems.IndexOf(eq)>=0 then eq.FFlag_NoDrop:=nodropflag;
found:=true;
goto done;
end;
itemtype:=TItemType(av[2].VInt);
ExlplotableState:=false;
if High(av)>=3 then ExlplotableState:=boolean(av[3].VInt);
for i:=0 to ship.FEquipments.Count-1 do begin
eq:=ship.FEquipments.Items[i];
if (eq.FItemType=itemtype) and (eq.FExplotable=ExlplotableState) then begin
if High(av)>=4 then begin
sitem:=TScriptItem(av[4].VDW);
if sitem.FItem<>nil then sitem.FItem.FScriptItem:=nil;
sitem.FItem:=eq;
eq.FScriptItem:=sitem;
end;
nodropflag:=eq.FFlag_NoDrop;
eq.FFlag_NoDrop:=0;
ship.DropEx(eq);
if ship.FCurStar.FItems.IndexOf(eq)>=0 then eq.FFlag_NoDrop:=nodropflag;
found:=true;
goto done;
end;
end;
for i:=0 to ship.FArtefacts.Count-1 do begin
eq:=ship.FArtefacts.Items[i];
if (eq.FItemType=itemtype) and (eq.FExplotable=ExlplotableState) then begin
if High(av)>=4 then begin
sitem:=TScriptItem(av[4].VDW);
if sitem.FItem<>nil then sitem.FItem.FScriptItem:=nil;
sitem.FItem:=eq;
eq.FScriptItem:=sitem;
end;
nodropflag:=eq.FFlag_NoDrop;
eq.FFlag_NoDrop:=0;
ship.DropEx(eq);
if ship.FCurStar.FItems.IndexOf(eq)>=0 then eq.FFlag_NoDrop:=nodropflag;
found:=true;
goto done;
end;
end;
done:
if not found then raise Exception.Create('Error.Script SF_DropItem - item not found');
end;
procedure SF_DropScriptItem(av:array of TVarEC; code:TCodeEC);
var
ship:TShip;
sitem:TScriptItem;
nodropflag:integer;
begin
if High(av)<>2 then raise Exception.Create('Error.Script DropScriptItem');
ship:=TShip(av[1].VDW);
sitem:=TScriptItem(av[2].VDW);
if sitem.FItem=nil then Exit;
if (ship.FEquipments.IndexOf(sitem.FItem)<0) and (ship.FArtefacts.IndexOf(sitem.FItem)<0) then Exit;
if not ship.InNormalSpace then Exit;
nodropflag:=sitem.FItem.FFlag_NoDrop;
sitem.FItem.FFlag_NoDrop:=0;
ship.DropEx(sitem.FItem);
if sitem.FItem<>nil then sitem.FItem.FFlag_NoDrop:=nodropflag;
end;
procedure SF_DeleteEquipment(av:array of TVarEC; code:TCodeEC);
var
i:integer;
ship:TShip;
eq:TEquipment;
type_eq:TItemType;
begin
if High(av)<>2 then raise Exception.Create('Error.Script SF_DeleteEquipment');
ship:=TShip(av[1].VDW);
i:=0;
type_eq:=TItemType(av[2].VInt);
while i<ship.FEquipments.Count do begin
eq:=ship.FEquipments.Items[i];
if (eq.FScriptItem=nil)and(eq.FItemType=type_eq) then begin
ship.FEquipments.Delete(i);
eq.Free;
end else inc(i);
end;
//ship.ArrangeEquipments;
ship.CalcParam;
end;
procedure SF_Rnd(av:array of TVarEC; code:TCodeEC);
var
min,max:integer;
t:cardinal;
begin
if High(av)<2 then raise Exception.Create('Error.Script Rnd');
if High(av)>2 then begin t:=av[3].VDW; av[0].VInt:=RndOut(av[1].VInt,av[2].VInt,t); end
else if Galaxy<>nil then av[0].VInt:=RndOut(av[1].VInt,av[2].VInt,Galaxy.FRndOut)
else begin
min:=av[1].VInt;
max:=av[2].VInt;
av[0].VInt:=min+Random(max-min+1);
end;
end;
procedure SF_GameDateTxtByTurn(av:array of TVarEC; code:TCodeEC);
begin
if High(av)<>1 then raise Exception.Create('Error.Script GameDateTxtByTurn');
av[0].VStr:=GameDateTxtG(av[1].VInt);
end;
procedure SF_StatusPlayer(av:array of TVarEC; code:TCodeEC);
begin
case Player.Status of
Trader: av[0].VInt:=1;
Warrior: av[0].VInt:=0;
Pirate: av[0].VInt:=-1;
end;
end;
procedure SF_Id(av:array of TVarEC; code:TCodeEC);
var
obj: TObject;
begin
if(High(av) <> 1) then raise Exception.Create('Error.Script SF_Id');
obj:=TObject(av[1].VDW);
if(obj is TShip) then begin
av[0].VDW:=TShip(obj).FId;
end else if(obj is TPlanet) then begin
av[0].VDW:=TPlanet(obj).FId;
end else if(obj is TStar) then begin
av[0].VDW:=TStar(obj).FId;
end else if(obj is TConstellation) then begin
av[0].VDW:=TConstellation(obj).FId;
end else if(obj is TItem) then begin
av[0].VDW:=TItem(obj).FId;
end else if(obj is THole) then begin
av[0].VDW:=THole(obj).FId;
end else if(obj is TMissile) then begin
av[0].VDW:=TMissile(obj).FId;
end else if(obj is TAsteroid) then begin
av[0].VDW:=TAsteroid(obj).FId;
end else raise Exception.Create('Error.Script SF_Id 2');
end;
procedure SF_GalaxyMoney(av:array of TVarEC; code:TCodeEC);
var
own:TOwner;
begin
if High(av)<1 then raise Exception.Create('Error.Script SF_GalaxyMoney');
own:=People;
if High(av)>=2 then own:=TOwner(av[2].VInt);
case av[1].VInt of
0: av[0].VInt:=Galaxy.MiniMoney(own);
1: av[0].VInt:=Galaxy.SmallMoney(own);
2: av[0].VInt:=Galaxy.AverageMoney(own);
3: av[0].VInt:=Galaxy.BigMoney(own);
4: av[0].VInt:=Galaxy.HugeMoney(own);
else
raise Exception.Create('Error.Script SF_GalaxyMoney');
end;
end;
procedure SF_SetName(av:array of TVarEC; code:TCodeEC);
var
obj:TObject;
begin
if High(av)<>2 then raise Exception.Create('Error.Script SF_SetName');
obj:=TObject(av[1].VDW);
if obj is TShip then TShip(obj).FName:=av[2].VStr
else if obj is TPlanet then TPlanet(obj).FName:=av[2].VStr
else if obj is TStar then TStar(obj).FName:=av[2].VStr
else if obj is TItem then TItem(obj).FName:=av[2].VStr;
end;
procedure SF_UseTranclucator(av:array of TVarEC; code:TCodeEC);
var
ship:TShip;
art:TArtefact;
tart:TArtefactTranclucator;
tran:TTranclucator;
i:integer;
angle:single;
begin
if High(av)<1 then raise Exception.Create('Error.Script SF_UseTranclucator');
av[0].VDW:=0;
ship:=TShip(av[1].VDW);
if ship.InHyperSpace then exit;
art:=nil;
if High(av)>1 then art:=TArtefact(av[2].VDW)
else
for i:=0 to ship.FArtefacts.Count-1 do
begin
art:=ship.FArtefacts.Items[i];
if art is TArtefactTranclucator and not(art.FBroken) then break;
end;
if (art=nil) or not (art is TArtefactTranclucator) then exit;
tart:= art as TArtefactTranclucator;
tran:=TTranclucator(tart.FShip);
tart.FShip := nil;
tran.FCurStar := ship.FCurStar;
ship.FCurStar.FShips.Add(tran);
if ship.InNormalSpace then
begin
angle := Rnd(0, 360, ship.FCurStar.FRnd * Galaxy.FTurn * integer(tran.FId)) * pi / 180;
tran.FPos.x := ship.FPos.x + sin(angle) * 100;
tran.FPos.y := ship.FPos.y - cos(angle) * 100;
end
else
if ship.FCurPlanet<>nil then tran.FCurPlanet:=ship.FCurPlanet
else if ship.FCurShip<>nil then tran.FCurShip:=ship.FCurShip;
tran.FGraphShip.Pos := tran.FPos;
tran.FProprietor := ship;
i:=ship.FArtefacts.IndexOf(tart);
if i>=0 then ship.FArtefacts.Delete(i);
i:=ship.FEquipments.IndexOf(tart);
if i>=0 then ship.FEquipments.Delete(i);
tart.Free;
ship.CalcParam;
tran.NextDay;
//Player.FAchievementStats.CheckConditionAchTranclucators();
av[0].VDW:=Cardinal(tran);
end;
procedure SF_HullDamage(av:array of TVarEC; code:TCodeEC);
var
obj:TObject;
hull:THull;
begin
if High(av)<>1 then raise Exception.Create('Error.Script HullDamage');
obj:=TObject(av[1].VDW);
if obj is TShip then hull:=TShip(obj).FHull
else if obj is TScriptItem then hull:=THull(TScriptItem(obj).FItem)
else hull:=THull(obj);
av[0].VInt:=100-Round((hull.FHitPoints/hull.FSize)*100);
end;
procedure SF_Hitpoints(av:array of TVarEC; code:TCodeEC);
var
obj:TObject;
hull:THull;
begin
if High(av)<>1 then raise Exception.Create('Error.Script Hitpoints');
obj:=TObject(av[1].VDW);
if obj is TShip then hull:=TShip(obj).FHull
else if obj is TScriptItem then hull:=THull(TScriptItem(obj).FItem)
else hull:=THull(obj);
av[0].VInt:=hull.FHitPoints;
end;
procedure SF_Hit(av:array of TVarEC; code:TCodeEC);
var
ship:TShip;
begin
if High(av)<1 then ship:=GScriptCur.FCurScriptShip
else ship:=TShip(av[1].VDW);
if ship=nil then Exit;
with SctiptGetSS(ship,GScriptCur) do
begin
if High(av)<2 then
begin
av[0].VInt:=integer(FHit or FHitPlayer);
end
else if av[2].VInt<>0 then
begin
av[0].VInt:=integer(FHitPlayer);
if High(av)>2 then FHitPlayer:=av[3].VInt<>0;
end
else
begin
av[0].VInt:=integer(FHit);
if High(av)>2 then FHit:=av[3].VInt<>0;
end;
end;
//changed
//Hit(ship) - check if ship damaged player or player damaged ship (with weapon or explosion)
//Hit(ship,1) - check if ship damaged player
//Hit(ship,0) - check if player damaged ship
end;
procedure SF_ChangeGlobalRelationsShips(av:array of TVarEC; code:TCodeEC);
var
ship:TShip;
obj:TObject;
rct:TRelationChange;
sst:TSetSShipType;
so:TSetOwner;
begin
if High(av)<>6 then raise Exception.Create('Error.Script ChangeGlobalRelationsShips');
if av[1].VDW=0 then Exit;
ship:=TShip(av[1].VDW);
if (ship=nil) or (not (ship is TRanger)) then Exit;
if (av[2].VDW>0) and (av[2].VDW<255) then obj:=TScriptConstellation(GScriptCur.FConstellation.Items[av[2].VDW]).FConstellation
else if av[2].VDW<>0 then obj:=TObject(av[2].VDW)
else obj:=nil;
case av[3].VDW of
0: rct:=RelationsToMin;
1: rct:=RelationsToMax;
2: rct:=RelationsPercentAdd;
3: rct:=RelationsPercentDec;
else
rct:=RelationsToMin;
end;
sst:=TSetSShipType(Word(av[5].VDW));
so:=TSetOwner(Byte(av[6].VDW));
TRanger(ship).ChangeGlobalRelationsShips(obj,rct,av[4].VInt,sst,so);
end;
procedure SF_ChangeGlobalRelationsPlanets(av:array of TVarEC; code:TCodeEC);
var
ship:TShip;
obj:TObject;
rct:TRelationChange;
so:TSetOwner;
begin
if High(av)<>5 then raise Exception.Create('Error.Script ChangeGlobalRelationsPlanets');
ship:=TShip(av[1].VDW);
if (ship=nil) or (not (ship is TRanger)) then Exit;
if (av[2].VDW>0) and (av[2].VDW<255) then obj:=TScriptConstellation(GScriptCur.FConstellation.Items[av[2].VDW]).FConstellation
else if av[2].VDW<>0 then obj:=TObject(av[2].VDW)
else obj:=nil;
case av[3].VDW of
0: rct:=RelationsToMin;
1: rct:=RelationsToMax;
2: rct:=RelationsPercentAdd;
3: rct:=RelationsPercentDec;
else
rct:=RelationsToMin;
end;
so:=TSetOwner(Byte(av[5].VDW));
TRanger(ship).ChangeGlobalRelationsPlanets(obj,rct,av[4].VInt,so);
end;
procedure SF_GlobalRelationsShips(av:array of TVarEC; code:TCodeEC);
var
ship:TShip;
obj:TObject;
sst:TSetSShipType;
so:TSetOwner;
begin
if High(av)<>4 then raise Exception.Create('Error.Script GlobalRelationsShips');
ship:=TShip(av[1].VDW);
if (ship=nil) or (not (ship is TRanger)) then Exit;
if (av[2].VDW>0) and (av[2].VDW<255) then obj:=TScriptConstellation(GScriptCur.FConstellation.Items[av[2].VDW]).FConstellation
else if av[2].VDW<>0 then obj:=TObject(av[2].VDW)
else obj:=nil;
sst:=TSetSShipType(Word(av[3].VDW));
so:=TSetOwner(Byte(av[4].VDW));
av[0].VInt:=TRanger(ship).GlobalRelationsShips(obj,sst,so);
end;
procedure SF_GlobalRelationsPlanets(av:array of TVarEC; code:TCodeEC);
var
ship:TShip;
obj:TObject;
so:TSetOwner;
begin
if High(av)<>3 then raise Exception.Create('Error.Script GlobalRelationsPlanets');
ship:=TShip(av[1].VDW);
if (ship=nil) or (not (ship is TRanger)) then Exit;
if (av[2].VDW>0) and (av[2].VDW<255) then obj:=TScriptConstellation(GScriptCur.FConstellation.Items[av[2].VDW]).FConstellation
else if av[2].VDW<>0 then obj:=TObject(av[2].VDW)
else obj:=nil;
so:=TSetOwner(Byte(av[3].VDW));
av[0].VInt:=TRanger(ship).GlobalRelationsPlanets(obj,so);
end;
procedure SF_SetRelationGroup(av:array of TVarEC; code:TCodeEC);
begin
if High(av)<>3 then raise Exception.Create('Error.Script SetRelationGroup');
GScriptCur.SetRelationGroup(av[1].VInt,av[2].VInt,TRelationType(av[3].VInt));
end;
procedure SF_SetRelationPlanet(av:array of TVarEC; code:TCodeEC);
begin
if High(av)<>3 then raise Exception.Create('Error.Script SetRelationPlanet');
GScriptCur.SetRelationPlanet(av[2].VInt,TPlanet(av[1].VDW),TRelationType(av[3].VInt));
end;
procedure SF_GetRelationPlanet(av:array of TVarEC; code:TCodeEC);
var
planet:TPlanet;
begin
if High(av)<>2 then raise Exception.Create('Error.Script GetRelationPlanet');
planet:=TPlanet(av[1].VDW);
av[0].VDW:=planet.RelationToShip(TShip(av[2].VDW));
end;
procedure SF_CurTurn(av:array of TVarEC; code:TCodeEC);
begin
av[0].VInt:=Galaxy.FTurn;
if High(av)>0 then Galaxy.FTurn:=av[1].VInt;
end;
procedure SF_ShipType(av:array of TVarEC; code:TCodeEC);
var
ship:TShip;
begin
if High(av)<1 then raise Exception.Create('Error.Script ShipType');
ship:=TShip(av[1].VDW);
if ship=Player.FBridge then av[0].VStr:='PlayerBridge'
else if ship.FCustomTypeName<>'' then av[0].VStr:=ship.FCustomTypeName
else if (ship.FScriptShip<>nil) and
(TScriptShip(ship.FScriptShip).FScript.FCD = 'Script.PC_fem_rangers') and
(TScriptShip(ship.FScriptShip).GetOGroup.FName='GroupFem') then av[0].VStr:='FemRanger'
else av[0].VStr:=ship.TypeName;
if High(av)>1 then
begin
if av[2].VStr=ship.TypeName then ship.FCustomTypeName:=''
else ship.FCustomTypeName:=av[2].VStr;
end;
end;
procedure SF_ConName(av:array of TVarEC; code:TCodeEC);
var
con:TConstellation;
begin
if High(av)<>1 then raise Exception.Create('Error.Script ConName');
if av[1].VDW < Cardinal(Galaxy.FConstellation.Count) then con:=Galaxy.FConstellation[av[1].VDW]
else con:=TConstellation(av[1].VDW);
av[0].VStr:=con.Name;
end;
procedure SF_StarName(av:array of TVarEC; code:TCodeEC);
var
star:TStar;
begin
if High(av)<>1 then raise Exception.Create('Error.Script StarName');
star:=TStar(av[1].VDW);
av[0].VStr:=star.FName;
end;
procedure SF_StarMapLabel(av:array of TVarEC; code:TCodeEC);
var
star:TStar;
begin
if High(av)<1 then raise Exception.Create('Error.Script StarMapLabel');
star:=TStar(av[1].VDW);
av[0].VStr:=star.FMapLabel;
if High(av)>1 then star.FMapLabel:=av[2].VStr;
end;
procedure SF_PlanetName(av:array of TVarEC; code:TCodeEC);
var
planet:TPlanet;
begin
if High(av)<>1 then raise Exception.Create('Error.Script PlanetName');
planet:=TPlanet(av[1].VDW);
av[0].VStr:=planet.FName;
end;
procedure SF_IdToPlanet(av:array of TVarEC; code:TCodeEC);
var
planet:TPlanet;
begin
if High(av)<>1 then raise Exception.Create('Error.Script IdToPlanet');
av[0].VDW:=Cardinal(Galaxy.IdToPlanet(av[1].VDW));
end;
procedure SF_IdToShip(av:array of TVarEC; code:TCodeEC);
var
ship:TShip;
begin
if High(av)<1 then raise Exception.Create('Error.Script IdToShip');
av[0].VDW:=Cardinal(Galaxy.IdToShip(av[1].VDW, (High(av)>1) and (av[2].VInt<>0) ));
end;
procedure SF_IdToItem(av:array of TVarEC; code:TCodeEC);
var
ship:TShip;
begin
if High(av)<>1 then raise Exception.Create('Error.Script IdToItem');
av[0].VDW:=Cardinal(Galaxy.IdToItem(av[1].VDW, false));
end;
procedure SF_PlanetSetGoods(av:array of TVarEC; code:TCodeEC);
var
it:tItemType;
begin
if High(av)<>3 then raise Exception.Create('Error.Script PlanetSetGoods');
it:=TItemType(av[2].VInt);