-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathservices.pp
2217 lines (1882 loc) · 72.9 KB
/
services.pp
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 services;
{ This is an offshoot of the ArenaTalk/ArenaScript interaction }
{ stuff. It's supposed to handle shops & other cash transactions }
{ for the GearHead RPG engine. }
{
GearHead2, a roguelike mecha CRPG
Copyright (C) 2005 Joseph Hewitt
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at
your option) any later version.
The full text of the LGPL can be found in license.txt.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
}
{$LONGSTRINGS ON}
interface
uses gears,locale;
const
num_standard_schemes = 5;
standard_lot_colors: Array [0..num_standard_schemes-1] of string = (
'152 172 183 199 188 162 200 0 200', { Coral, Gull Grey, Purple }
' 80 80 85 130 144 114 200 200 0', { Dark Grey, Battleship Grey, Yellow }
' 66 121 179 210 215 80 205 25 0', { Default player colors }
'201 205 229 49 91 161 0 200 0', { Aero Blue, Azure, Green }
'240 240 240 208 34 51 50 50 150' { White, Red Goes Fasta, Blue }
);
SATT_SaleTag = 'SALETAG';
var
{ The following vars are primarily needed by the interaction routines in }
{ arenascript.pp, but they're needed here too and this is the higher level }
{ unit so here they are. }
CHAT_Message: String; { The message in the interact window. }
CHAT_React: Integer; { How the NPC feels about the PC. }
I_Endurance: Integer; { How much of the PC's crap the NPC is }
{ willing to take. When it reaches 0, the NPC says goodbye. }
Function Random_Mecha_Colors: String;
Function RepairMasterCost( Master: GearPtr; Material: Integer ): LongInt;
Function ReloadMasterCost( M: GearPtr; ReloadGeneralInv: Boolean ): LongInt;
Procedure DoReloadMaster( M: GearPtr; ReloadGeneralInv: Boolean );
Procedure OpenShop( GB: GameBoardPtr; PC,NPC: GearPtr; Stuff: String );
Procedure OpenSchool( GB: GameBoardPtr; PC,NPC: GearPtr; Stuff: String );
Procedure ExpressDelivery( GB: GameBoardPtr; PC,NPC: GearPtr );
Procedure ShuttleService( GB: GameBoardPtr; PC,NPC: GearPtr );
implementation
uses ability,arenacfe,backpack,gearutil,ghchars,ghmodule,gearparser,
ghswag,ghweapon,interact,menugear,rpgdice,skilluse,texutil,
description,narration,ui4gh,ghprop,
customization,
{$IFDEF ASCII}
vidgfx,vidmap,vidmenus,vidinfo;
{$ELSE}
sdlgfx,sdlmap,sdlmenus,sdlinfo,colormenu;
{$ENDIF}
Const
MaxShopItems = 21; { Maximum number of items in a shop. }
{ Repair Mode Constants }
RM_Medical = 1; { Repair MEAT for SF:0 }
RM_GeneralRepair = 2; { Repair METAL and BIOTECH for SF:0 }
RM_MechaRepair = 3; { Repair METAL and BIOTECH for higher SF }
var
SERV_GB: GameBoardPtr;
SERV_PC,SERV_NPC,SERV_Info,SERV_CUSTOMER: GearPtr;
SERV_Menu: RPGMenuPtr;
Standard_Caliber_List: GearPtr;
Procedure BasicServiceRedraw;
{ Redraw the services interface without any of the bells and whistles. }
begin
CombatDisplay( SERV_GB );
SetupServicesDisplay();
{$IFDEF ASCII}
if SERV_NPC <> Nil then NPCPersonalInfo( SERV_NPC , ZONE_ShopCaption );
CMessage( '$' + BStr( NAttValue( SERV_PC^.NA , NAG_Experience , NAS_Credits ) ) , ZONE_ItemsPCInfo , InfoHilight );
GameMsg( CHAT_Message , ZONE_ShopMsg , InfoHiLight );
{$ELSE}
if SERV_NPC <> Nil then begin
DrawPortrait( SERV_GB, SERV_NPC, ZONE_ShopNPCPortrait.GetRect(), False );
CMessage( GearName(SERV_NPC) , ZONE_ShopNPCName.GetRect() , InfoHilight );
end;
DrawPortrait( SERV_GB, SERV_Customer, ZONE_ShopPCPortrait.GetRect(), False );
CMessage( GearName(SERV_Customer) , ZONE_ShopPCName.GetRect() , InfoHilight );
CMessage( '$' + BStr( NAttValue( SERV_PC^.NA , NAG_Experience , NAS_Credits ) ) , ZONE_ShopCash.GetRect() , InfoHilight );
GameMsg( CHAT_Message , ZONE_ShopText.GetRect() , InfoHiLight );
{$ENDIF}
end;
Procedure ServiceRedraw;
{ Redraw the screen for whatever service is going to go on. }
var
Part: GearPtr;
begin
BasicServiceRedraw();
if ( SERV_Info <> Nil ) and ( Serv_Menu <> Nil ) then begin
Part := RetrieveGearSib( SERV_Info , CurrentMenuItemValue( SERV_Menu ) );
if Part <> Nil then begin
BrowserInterfaceInfo( SERV_GB , Part , ZONE_ShopInfo );
end;
end else if Serv_Info <> Nil then begin
BrowserInterfaceInfo( SERV_GB , SERV_Info , ZONE_ShopInfo );
end;
end;
Procedure BrowseTreeRedraw;
{ Redraw the screen for whatever service is going to go on. }
var
Part: GearPtr;
N: Integer;
begin
BasicServiceRedraw();
if ( SERV_Info <> Nil ) and ( Serv_Menu <> Nil ) then begin
N := CurrentMenuItemValue( SERV_Menu );
if N > 0 then begin
Part := LocateGearByNumber( SERV_Info , N );
if Part <> Nil then begin
BrowserInterfaceInfo( SERV_GB , Part , ZONE_ShopInfo );
end;
end;
end else if Serv_Info <> Nil then begin
BrowserInterfaceInfo( SERV_GB , SERV_Info , ZONE_ShopInfo );
end;
end;
Procedure SellStuffRedraw;
{ Redraw the screen for whatever service is going to go on. }
var
N: Integer;
Part: GearPtr;
begin
BasicServiceRedraw();
if ( SERV_Info <> Nil ) and ( Serv_Menu <> Nil ) then begin
N := CurrentMenuItemValue( SERV_Menu );
if N > 0 then begin
Part := LocateGearByNumber( SERV_Info , N );
if Part <> Nil then begin
BrowserInterfaceInfo( SERV_GB , Part , ZONE_ShopInfo );
end;
end;
end else if Serv_Info <> Nil then begin
BrowserInterfaceInfo( SERV_GB , SERV_Info , ZONE_ShopInfo );
end;
end;
Procedure ServicesBackpackRedraw;
{ A redrawer for the backpack, as accessed from services. }
{ Just do the combat display and call it even. }
begin
CombatDisplay( SERV_GB );
end;
Function ScalePrice( GB: GameBoardPtr; PC,NPC: GearPtr; Price: Int64 ): LongInt;
{ Modify the price listed based upon the PC's shopping skill, }
{ faction membership, and whatever else. }
var
ShopRk,ShopTr,R: Integer; { ShopRank and ShopTarget }
PriceMod: LongInt;
Adv: GearPtr;
begin
{ Start with the assumption that we're paying 100%. }
PriceMod := 100;
{ First, let's modify this by Shopping skill. }
{ Determine the Shopping skill rank of the buyer. }
ShopRk := SkillValue( PC , NAS_Shopping , STAT_Charm );
{ Determine the shopping target number, which should be the EGO }
{ stat of the storekeeper. }
if ( NPC = Nil ) or ( NPC^.G <> GG_Character ) then ShopTr := 10
else begin
{ Target is based on both the Ego of the shopkeeper }
{ and also on the relationship with the PC. }
ShopTr := CStat( NPC , STAT_Ego );
R := ReactionScore( Nil , PC , NPC );
if R > 0 then begin
ShopTr := ShopTr - ( R div 5 );
end else if R < 0 then begin
{ It's much harder to haggle if the shopkeep }
{ doesn't like you. }
ShopTr := ShopTr + Abs( R ) div 2;
{ If the dislike ventures into hate, there's a markup. }
if R < -20 then PriceMod := PriceMod + Abs( R ) div 5;
end;
end;
{ If ShopRk beats ShopTr, lower the asking price. }
if ShopRk > ShopTr then begin
{ Every point of shopping skill that the unit has }
{ gives a 2% discount to whatever is being purchased. }
ShopRk := ( ShopRk - ShopTr ) * 2;
if ShopRk > 50 then ShopRk := 50;
PriceMod := PriceMod - ShopRk;
end;
{ Next, let's take a look at factions. }
if ( GB <> Nil ) and ( GB^.Scene <> Nil ) and ( NPC <> Nil ) then begin
{ ArchEnemies get a 20% markup, allies get a 10% discount. }
Adv := FindRoot( GB^.Scene );
if IsArchEnemy( Adv , NPC ) then begin
PriceMod := PriceMod + 20;
end else if IsArchAlly( Adv , NPC ) then begin
PriceMod := PriceMod - 10;
end;
end;
{ Calculate the final price. }
Price := ( Price * PriceMod ) div 100;
if Price < 1 then Price := 1;
ScalePrice := Price;
end;
Function MaxShopRank( Shopkeeper: GearPtr ): Integer;
{ Return the maximum shop rank normally stocks. }
var
MSR: Integer;
begin
MSR := SkillRank( Shopkeeper , NAS_Shopping ) - 3;
if MSR < 3 then MSR := 3;
MaxShopRank := MSR;
end;
Function PurchasePrice( GB: GameBoardPtr; PC,NPC,Item: GearPtr ): LongInt;
{ Determine the purchase price of ITEM as being sold by NPC }
{ to PC. }
begin
{ Scale the base cost for the item. }
PurchasePrice := ScalePrice( GB , PC , NPC , GearCost( Item ) );
end;
Procedure ShoppingXP( PC , Part: GearPtr );
{ The PC has just purchased PART. Give some XP to the PC's shopping }
{ skill, then print a message if appropriate. }
var
Price: LongInt;
begin
{ Find the price of the gear. This must be positive or it'll }
{ crash the logarithm function. }
Price := GearCost( Part );
if Price < 1 then Price := 1;
if DoleSkillExperience( PC , NAS_Shopping , Round( Ln( Price ) * 5 ) + 1 ) then begin
DialogMsg( MsgString( 'SHOPPING_SkillAdvance' ) );
end;
end;
Function ShopTolerance( GB: GameBoardPtr; NPC: GearPtr ): Integer;
{ Tolerance measures the legality/illegality of items. This function }
{ returns the maximum legality level stocked by this shopkeeper. }
var
Scene: GearPtr;
Tolerance: Integer;
begin
if ( GB <> Nil ) and ( GB^.Scene <> Nil ) then begin
Scene := FindRootScene( GB^.Scene );
if AStringHasBSTring( SAttValue( GB^.Scene^.SA , 'SPECIAL' ) , 'UNREGULATED' ) then begin
Tolerance := NAttValue( GB^.Scene^.NA , NAG_GearOps , NAS_Legality );
end else begin
Tolerance := NAttValue( Scene^.NA , NAG_GearOps , NAS_Legality );
end;
{ Criminal shopkeepers have a higher than normal tolerance. }
if NAttValue( NPC^.NA , NAG_CharDescription , NAS_Lawful ) < 0 then begin
Tolerance := Tolerance - ( NAttValue( NPC^.NA , NAG_CharDescription , NAS_Lawful ) div 2 ) + 5;
end;
end else begin
Tolerance := 0;
end;
ShopTolerance := Tolerance;
end;
procedure BuyAmmoClips( GB: GameBoardPtr; PC,NPC,Weapon: GearPtr );
{ Allow spare clips to be purchased for this weapon. }
{ If possible, add some special clip types. }
var
AmmoList: GearPtr;
Tolerance: Integer;
Function HasUniqueType( Ammo: GearPtr ): Boolean;
{ Return TRUE if Ammo has a TYPE attribute tag which WEAPON lacks. }
var
WType,AType,msg: String;
UTypeFound: Boolean;
begin
WType := WeaponAttackAttributes( Weapon );
AType := SAttValue( Ammo^.SA , 'TYPE' );
{ If you've got an ammo that does nothing and normal ammo that does something, }
{ that ammo counts as having a unique type. }
if ( AType = '' ) and ( WType <> '' ) then Exit( True );
UTypeFound := False;
while ( AType <> '' ) and not UTypeFound do begin
msg := ExtractWord( AType );
if not AStringHasBString( WType , msg ) then UTypeFound := True;
end;
HasUniqueType := UTypeFound;
end;
Procedure AddAmmoToList( Proto: GearPtr );
{ Create a clone of this ammunition and add it to the list. }
{ If appropriate, add some ammo variants. We will assume for the }
{ purpose of this procedure that no item will ever have multiple }
{ ammo clips of the same type; i.e. you would not have a 5mm rifle }
{ which also had an integrated 5mm rifle built into it. If you }
{ design a weapon like that you are a truly terrible person, and }
{ I wash my hands of you. }
var
A,ATmp,AVar,VarList: GearPtr;
begin
A := CloneGear( Proto );
AppendGear( AmmoList , A );
{ Depending on the caliber of this ammo, and the shopkeeper's stats, }
{ maybe add some variants. }
VarList := SeekGearByName( Standard_Caliber_List , SAttValue( A^.SA , 'CALIBER' ) );
if VarList <> Nil then begin
AVar := VarList^.SubCom;
while AVar <> Nil do begin
if ( NAttValue( AVar^.NA , NAG_GearOps , NAS_Legality ) <= Tolerance ) and HasUniqueType( AVar ) then begin
ATmp := CloneGear( A );
SetSAtt( ATmp^.SA , 'name <' + GearName( A ) + ' (' + GearName( AVar ) + ')>' );
SetSAtt( ATmp^.SA , 'type <' + SAttValue( AVar^.SA , 'TYPE' ) + '>' );
AppendGear( AmmoList , ATmp );
end;
AVar := AVar^.Next;
end;
end;
end;
Procedure LookForAmmo( LList: GearPtr );
{ Search along this linked list looking for ammo. If you find }
{ any, copy it and add it to the list. Then, add any ammo varieties }
{ allowed by the shopkeeper's skill level and tolerance. }
begin
while LList <> Nil do begin
if LList^.G = GG_Ammo then begin
AddAmmoToList( LList );
end;
LookForAmmo( LList^.SubCom );
LList := LList^.Next;
end;
end;
var
ShopMenu: RPGMenuPtr;
Ammo: GearPtr;
N: Integer;
Cost: LongInt;
begin
{ Step One: Create the list of ammo. }
AmmoList := Nil;
Tolerance := ShopTolerance( GB , NPC );
LookForAmmo( Weapon^.SubCom );
{ Step Two: Create the shopping menu. }
ShopMenu := CreateRPGMenu( MenuItem , MenuSelect , ZONE_ShopMenu );
N := 1;
Ammo := AmmoList;
while Ammo <> Nil do begin
AddRPGMenuItem( ShopMenu , GearName( Ammo ) + ' ($' + BStr( PurchasePrice( GB , PC , NPC , Ammo ) ) + ')' , N );
Inc( N );
Ammo := Ammo^.Next;
end;
RPMSortAlpha( ShopMenu );
AlphaKeyMenu( ShopMenu );
AddRPGMenuItem( ShopMenu , MsgString( 'EXIT' ) , -1 );
{ Step Three: Keep shopping until the PC selects exit. }
repeat
SERV_Info := AmmoList;
SERV_Menu := ShopMenu;
N := SelectMenu( ShopMenu , @ServiceRedraw );
if N > 0 then begin
Ammo := RetrieveGearSib( AmmoList , N );
Cost := PurchasePrice( GB , PC , NPC , Ammo );
if NAttValue( PC^.NA , NAG_Experience , NAS_Credits ) >= Cost then begin
{ Copy the gear, then stick it in inventory. }
Ammo := CloneGear( Ammo );
GivePartToPC( GB , Ammo , PC );
{ Reduce the buyer's cash by the cost of the gear. }
AddNAtt( PC^.NA , NAG_Experience , NAS_Credits , -Cost );
CHAT_Message := MsgString( 'BUYREPLY' + BStr( Random( 4 ) + 1 ) );
DialogMSG( ReplaceHash( MsgString( 'BUY_YOUHAVEBOUGHT' ) , GearName( Ammo ) ) );
{ Give some XP to the PC's SHOPPING skill. }
ShoppingXP( PC , Ammo );
end else begin
{ Not enough cash to buy... }
DialogMSG( ReplaceHash( MsgString( 'BUY_CANTAFFORD' ) , GearName( Ammo ) ) );
CHAT_Message := MsgString( 'BUYNOCASH' + BStr( Random( 4 ) + 1 ) );
end;
end;
until N = -1;
{ Upon exiting, dispose of the ammo list. }
DisposeRPGMenu( ShopMenu );
DisposeGear( AmmoList );
end;
procedure PurchaseGearMenu( GB: GameBoardPtr; PC,NPC,Part: GearPtr );
{ The PC may or may not want to buy PART. }
{ Show the price of this gear, and ask whether or not the }
{ player wants to make this purchase. }
{ If this item contains any SF:0 ammunition, offer to sell some }
{ backup clips as well. }
var
YNMenu: RPGMenuPtr;
Cost: LongInt;
N: Integer;
msg: String;
begin
Cost := PurchasePrice( GB , PC , NPC , Part );
YNMenu := CreateRPGMenu( MenuItem , MenuSelect , ZONE_ShopMenu );
AddRPGMenuItem( YNMenu , 'Buy ' + GearName( Part ) + ' ($' + BStr( Cost ) + ')' , 1 );
if ( Part^.SubCom <> Nil ) or ( Part^.InvCom <> Nil ) then AddRPGMenuItem( YNMenu , MsgString( 'SERVICES_BrowseParts' ) , 2 );
if ( SeekSubsByG( Part^.SubCom , GG_Ammo ) <> Nil ) and ( Part^.Scale = 0 ) then AddRPGMenuItem( YNMenu , MsgString( 'SERVICES_BuyClips' ) , 3 );
AddRPGMenuItem( YNMenu , 'Search Again' , -1 );
msg := MSgString( 'BuyPROMPT' + Bstr( Random( 4 ) + 1 ) );
msg := ReplaceHash( msg , GearName( Part ) );
msg := ReplaceHash( msg , BStr( Cost ) );
CHAT_Message := Msg;
repeat
Serv_Info := Part;
Serv_Menu := Nil;
N := SelectMenu( YNMenu , @ServiceRedraw );
if N = 1 then begin
if NAttValue( PC^.NA , NAG_Experience , NAS_Credits ) >= Cost then begin
{ Copy the gear, then stick it in inventory. }
Part := CloneGear( Part );
GivePartToPC( GB , Part , PC );
{ Reduce the buyer's cash by the cost of the gear. }
AddNAtt( PC^.NA , NAG_Experience , NAS_Credits , -Cost );
CHAT_Message := MsgString( 'BUYREPLY' + BStr( Random( 4 ) + 1 ) );
if ( NPC <> Nil ) and ( NAttValue( Part^.NA , NAG_GearOps , NAS_ShopRank ) >= ( MaxShopRank( NPC ) div 2 ) ) then begin
if DoleSkillExperience( NPC , NAS_Shopping , Random( SkillAdvCost( NPC , NAttValue( Part^.NA , NAG_GearOps , NAS_ShopRank ) + 3 ) ) + 1 ) then begin
CHAT_Message := CHAT_Message + ' ' + MsgString( 'BUYUPGRADE' );
end;
end;
DialogMSG( ReplaceHash( MsgString( 'BUY_YOUHAVEBOUGHT' ) , GearName( Part ) ) );
{ Give some XP to the PC's SHOPPING skill. }
ShoppingXP( PC , Part );
end else begin
{ Not enough cash to buy... }
DialogMSG( ReplaceHash( MsgString( 'BUY_CANTAFFORD' ) , GearName( Part ) ) );
CHAT_Message := MsgString( 'BUYNOCASH' + BStr( Random( 4 ) + 1 ) );
end;
end else if N = 2 then begin
MechaPartBrowser( Part , @ServiceRedraw );
end else if N = 3 then begin
BuyAmmoClips( GB , PC , NPC , Part )
end else if N = -1 then begin
CHAT_Message := MsgString( 'BUYCANCEL' + BStr( Random( 4 ) + 1 ) );
end;
until ( N <> 2 ) and ( N <> 3 );
DisposeRPGMenu( YNMenu );
end;
Function SellGear( var LList,Part: GearPtr; PC,NPC: GearPtr; const Categories: String ): Boolean;
{ The unit may or may not want to sell PART. }
{ Show the price of this gear, and ask whether or not the }
{ player wants to make this sale. }
var
YNMenu: RPGMenuPtr;
Cost: Int64;
R,ShopRk,ShopTr: Integer;
N: Integer;
WasStolen: Boolean;
msg: String;
begin
{ First - check to see whether or not the item is stolen. }
{ Most shopkeepers won't buy stolen goods. The PC has to locate }
{ a fence for illicit transactions. }
WasStolen := NAttValue( Part^.NA , NAG_NArrative , NAS_Stolen ) <> 0;
if WasStolen then begin
N := NAttValue( NPC^.NA , NAG_CharDescription , NAS_Lawful );
Cost := NAttValue( NPC^.NA , NAG_CharDescription , NAS_Heroic );
if Cost > 0 then N := N + Cost;
if N >= 0 then begin
{ This shopkeeper won't buy stolen items. }
CHAT_Message := MsgString( 'SERVICES_StolenResponse' );
DialogMsg( MsgString( 'SERVICES_StolenDesc' ) );
{ If the shopkeeper doesn't already hate the PC, }
{ then the PC's reputation and relation scores }
{ may both get damaged. }
if ( PC <> Nil ) and ( NAttValue( PC^.NA , NAG_ReactionScore , NAttValue( NPC^.NA , NAG_PErsonal , NAS_CID ) ) >= -20 ) then begin
AddReputation( PC , 2 , -1 );
if N > Random( 200 ) then AddReputation( PC , 6 , -1 );
AddNAtt( PC^.NA , NAG_ReactionScore , NAttValue( NPC^.NA , NAG_PErsonal , NAS_CID ) , -( Random( 6 ) + 1 ) );
end;
Exit( False );
end;
end;
Cost := GearCost( Part );
if Destroyed( Part ) then Cost := Cost div 3;
{ If this part matches the category of the shopkeeper, it's worth more money. }
{ Actually, it works so that selling inappropriate items are penalized. }
if not ( ( Part^.Scale < 1 ) and PartAtLeastOneMatch ( Categories , SAttValue( Part^.Sa , 'CATEGORY' ) ) ) then begin
Cost := ( Cost * 2 ) div 3;
end;
{ Determine shopping rank. }
ShopRk := SkillValue( PC , NAS_Shopping , STAT_Charm );
{ Determine shopping target. }
if ( NPC = Nil ) or ( NPC^.G <> GG_Character ) then ShopTr := 10
else begin
{ Target is based on both the Ego of the shopkeeper }
{ and also on the relationship with the PC. }
ShopTr := NPC^.Stat[ STAT_Ego ];
R := ReactionScore( Nil , PC , NPC );
if R > 0 then begin
ShopTr := ShopTr - ( R div 5 );
end else if R < 0 then begin
{ It's much harder to haggle if the shopkeep }
{ doesn't like you. }
ShopTr := ShopTr + Abs( R ) div 2;
end;
end;
{ Every point of shopping skill that the unit has }
{ gives a 1% bonus to the money gained. }
ShopRk := ShopRk - ShopTR;
if ShopRk > 40 then ShopRk := 40
else if ShopRk < 0 then ShopRk := 0;
Cost := ( Cost * (20 + ShopRk ) ) div 100;
if Cost < 1 then Cost := 1;
YNMenu := CreateRPGMenu( MenuItem , MenuSelect , ZONE_ShopMenu );
AddRPGMenuItem( YNMenu , 'Sell ' + GearName( Part ) + ' ($' + BStr( Cost ) + ')' , 1 );
AddRPGMenuItem( YNMenu , 'Maybe later' , -1 );
{ Query the menu - Sell it or not? }
msg := MSgString( 'SELLPROMPT' + Bstr( Random( 4 ) + 1 ) );
msg := ReplaceHash( msg , BStr( Cost ) );
msg := ReplaceHash( msg , GearName( Part ) );
CHAT_Message := Msg;
SERV_Menu := Nil;
SERV_Info := Part;
N := SelectMenu( YNMenu , @ServiceRedraw );
if N = 1 then begin
{ Increase the buyer's cash by the price of the gear. }
AddNAtt( PC^.NA , NAG_Experience , NAS_Credits , Cost );
CHAT_Message := MSgString( 'SELLREPLY' + Bstr( Random( 4 ) + 1 ) );
msg := MSgString( 'SELL_YOUHAVESOLD' );
msg := ReplaceHash( msg , GearName( Part ) );
msg := ReplaceHash( msg , BStr( Cost ) );
DialogMSG( msg );
{ If the item was stolen, trash the PC's reputation here. }
if WasStolen then begin
AddReputation( PC , 2 , -5 );
end;
RemoveGear( LList , Part );
end else begin
CHAT_Message := MSgString( 'SELLCANCEL' + Bstr( Random( 4 ) + 1 ) );
end;
DisposeRPGMenu( YNMenu );
SERV_Info := Nil;
SellGear := N = 1;
end;
Function RepairMasterCost( Master: GearPtr; Material: Integer ): LongInt;
{ Return the expected cost of repairing every component of }
{ MASTER which is made of MATERIAL. }
var
it: LongInt;
begin
it := TotalRepairableDamage( Master , Material ) * Repair_Cost_Multiplier[ Material ];
RepairMasterCost := it;
end;
Function RepairMasterByModeCost( Part: GearPtr; RepMode: Integer ): LongInt;
{ Determine how much it will cost to repair this master using the specified repair mode. }
{ If the mode doesn't affect this master, return 0. }
var
Cost: LongInt;
begin
Cost := 0;
if RepMode = RM_Medical then begin
Cost := RepairMasterCost( Part , NAV_Meat );
end else if ( RepMode = RM_GeneralRepair ) and ( Part^.Scale = 0 ) then begin
Cost := RepairMasterCost( Part , NAV_Metal ) + RepairMasterCost( Part , NAV_Biotech );
end else if ( RepMode = RM_MechaRepair ) and ( Part^.Scale > 0 ) then begin
Cost := RepairMasterCost( Part , NAV_Metal ) + RepairMasterCost( Part , NAV_Biotech );
end;
RepairMasterByModeCost := Cost;
end;
Function RepairAllCost( GB: GameBoardPtr; RepMode: Integer ): LongInt;
{ Determine the cost of repairing every item belonging to Team 1. }
var
Part: GearPtr;
Cost: longInt;
begin
{ Initialize values. }
Part := GB^.Meks;
Cost := 0;
{ Browse through each gear on the board, adding the cost to repair }
{ each Team 1 mek or character. }
while Part <> Nil do begin
if ( NAttValue( Part^.NA , NAG_Location , NAS_Team ) = NAV_DefPlayerTeam ) or ( NAttValue( Part^.NA , NAG_Location , NAS_Team ) = NAV_LancemateTeam ) then begin
{ Only repair mecha which have pilots assigned!!! }
{ If the PC had to patch up all that salvage every time... Brr... }
if ( Part^.G <> GG_Mecha ) or ( SAttValue( Part^.SA , 'PILOT' ) <> '' ) then begin
Cost := Cost + RepairMasterByModeCost( Part , RepMode );
end;
end;
Part := Part^.Next;
end;
RepairAllCost := Cost;
end;
Procedure DoRepairMaster( GB: GameBoardPtr; Master,Repairer: GearPtr; Material: Integer );
{ Remove the damage counters from every component of MASTER which }
{ can be affected using the provided SKILL. }
var
TRD: LongInt;
begin
{ Repair this part, if appropriate. }
TRD := TotalRepairableDamage( Master , Material );
ApplyRepairPoints( Master , Material , TRD , True );
{ Wait an amount of time. }
QuickTime( GB , AP_Minute * 5 );
end;
Procedure DoRepairMasterByMode( GB: GameBoardPtr; Part,NPC: GearPtr; RepMode: Integer );
{ Determine how much it will cost to repair this master using the specified repair mode. }
{ If the mode doesn't affect this master, return 0. }
begin
if RepMode = RM_Medical then begin
DoRepairMaster( GB , Part , NPC , NAV_Meat );
end else if ( RepMode = RM_GeneralRepair ) and ( Part^.Scale = 0 ) then begin
DoRepairMaster( GB , Part , NPC , NAV_Metal );
DoRepairMaster( GB , Part , NPC , NAV_Biotech );
end else if ( RepMode = RM_MechaRepair ) and ( Part^.Scale > 0 ) then begin
DoRepairMaster( GB , Part , NPC , NAV_Metal );
DoRepairMaster( GB , Part , NPC , NAV_Biotech );
end;
end;
Procedure DoRepairAll( GB: GameBoardPtr; NPC: GearPtr; RepMode: Integer );
{ Repair every item belonging to Team 1. }
var
Part: GearPtr;
begin
{ Initialize values. }
Part := GB^.Meks;
{ Browse through each gear on the board, repairing }
{ each Team 1 mek or character. }
while Part <> Nil do begin
if ( NAttValue( Part^.NA , NAG_Location , NAS_Team ) = NAV_DefPlayerTeam ) or ( NAttValue( Part^.NA , NAG_Location , NAS_Team ) = NAV_LancemateTeam ) then begin
{ Only repair mecha which have pilots assigned!!! }
{ If the PC had to patch up all that salvage every time... Brr... }
if ( Part^.G <> GG_Mecha ) or ( SAttValue( Part^.SA , 'PILOT' ) <> '' ) then begin
DoRepairMasterByMode( GB , Part , NPC , RepMode );
end;
end;
Part := Part^.Next;
end;
end;
Procedure RepairAllFrontEnd( GB: GameBoardPtr; PC, NPC: GearPtr; RepMode: Integer );
{ Run the REPAIR ALL procedure, and charge the PC for the work done. }
{ If the PC doesn't have enough money to repair everything roll to }
{ see if the NPC will do this work for free. }
const
NumRepairSayings = 5;
var
msg: String;
Cost,Cash: LongInt;
R: Integer;
begin
{ Determine the cost of repairing everything, and also }
{ the amount of cash the PC has. }
Cost := ScalePrice( GB , PC , NPC , RepairAllCost( GB , RepMode ) );
Cash := NAttValue( PC^.NA, NAG_Experience , NAS_Credits );
R := ReactionScore( Nil , PC , NPC );
msg := '';
{ See whether or not the PC will be charged for this repair. }
{ If the NPC likes the PC well enough, the service will be free. }
if ( Random( 200 ) + 10 ) < R then begin
{ The NPC will do the PC a favor, and do this one for free. }
msg := MsgString( 'SERVICES_RAFree' );
Cost := 0;
end else if ( Cash < Cost ) and ( R > ( 10 + NPC^.Stat[ STAT_Ego ] ) ) then begin
msg := MsgString( 'SERVICES_RACantPay' );
AddNAtt( PC^.NA , NAG_ReactionScore , NAttValue( NPC^.NA , NAG_Personal , NAS_CID ) , -Random( 10 ) );
Cost := 0;
end;
if Cost < Cash then begin
DoRepairAll( GB , NPC , RepMode );
AddNAtt( PC^.NA, NAG_Experience , NAS_Credits , -Cost );
if msg = '' then msg := MsgString( 'SERVICES_RADoRA' + BStr( Random( NumRepairSayings ) + 1 ) );
end else begin
msg := MsgString( 'SERVICES_RALousyBum' );
end;
CHAT_Message := msg;
end;
Procedure RepairOneFrontEnd( GB: GameBoardPtr; Part, PC, NPC: GearPtr; RepMode: Integer );
{ Run the REPAIR MASTER procedure, and charge the PC for the work done. }
{ If the PC doesn't have enough money to repair everything roll to }
{ see if the NPC will do this work for free. }
const
NumRepairSayings = 5;
var
Cost,Cash: LongInt;
R: Integer;
begin
{ Determine the cost of repairing everything, and also }
{ the amount of cash the PC has. }
Cost := ScalePrice( GB , PC , NPC , RepairMasterByModeCost( PArt , RepMode ) );
Cash := NAttValue( PC^.NA, NAG_Experience , NAS_Credits );
R := ReactionScore( Nil , PC , NPC );
{ See whether or not the PC will be charged for this repair. }
{ If the NPC likes the PC well enough, the service will be free. }
if ( Random( 90 ) + 10 ) < R then begin
{ The NPC will do the PC a favor, and do this one for free. }
CHAT_Message := MsgString( 'SERVICES_RAFree' );
Cost := 0;
end else if ( Cash < Cost ) and ( R > 10 ) then begin
CHAT_Message := MsgString( 'SERVICES_RACantPay' );
AddNAtt( PC^.NA , NAG_ReactionScore , NAttValue( NPC^.NA , NAG_Personal , NAS_CID ) , -Random( 5 ) );
Cost := 0;
end;
if Cost < Cash then begin
DoRepairMasterByMode( GB , Part , NPC , RepMode );
AddNAtt( PC^.NA, NAG_Experience , NAS_Credits , -Cost );
CHAT_Message := MSgString( 'SERVICES_RADoRA' + BStr( Random( NumRepairSayings ) + 1 ) );
end else begin
CHAT_Message := MsgString( 'SERVICES_RALousyBum' );
end;
end;
Function ReloadMagazineCost( Mag: GearPtr ): LongInt;
{ Calculate the cost of reloading this magazine. }
var
Spent: Integer;
it: LongInt;
begin
it := 0;
if Mag^.G = GG_Ammo then begin
Spent := NAttValue( Mag^.NA , NAG_WeaponModifier , NAS_AmmoSpent );
if Spent > 0 then begin
it := ( ComponentValue( Mag , True , True ) * Spent ) div Mag^.Stat[ STAT_AmmoPresent ];
if it < 5 then it := 5;
end;
end;
if it > 0 then begin
{ Reduce the reload cost by a factor of 5- apparently, magazines are really expensive. }
it := it div 5;
if it < 1 then it := 1;
end;
ReloadMagazineCost := it;
end;
Function ReloadMasterCost( M: GearPtr; ReloadGeneralInv: Boolean ): LongInt;
{ Return the cost of refilling all magazines held by M. }
var
Part: GearPtr;
it: LongInt;
begin
it := ReloadMagazineCost( M );
Part := M^.SubCom;
while Part <> Nil do begin
it := it + ReloadMasterCost( Part , ReloadGeneralInv );
Part := Part^.Next;
end;
if ReloadGeneralInv or not IsMasterGear( M ) then begin
Part := M^.InvCom;
while Part <> Nil do begin
it := it + ReloadMasterCost( Part , ReloadGeneralInv );
Part := Part^.Next;
end;
end;
ReloadMasterCost := it;
end;
Procedure DoReloadMaster( M: GearPtr; ReloadGeneralInv: Boolean );
{ Clear all ammo usage by M. }
var
Part: GearPtr;
begin
{ If this is an ammunition gear, set the number of shots fired to 0. }
if M^.G = GG_Ammo then SetNAtt( M^.NA , NAG_WeaponModifier , NAS_AmmoSpent , 0 );
{ Check SubComs and InvComs. }
Part := M^.SubCom;
while Part <> Nil do begin
DoReloadMaster( Part , ReloadGeneralInv );
Part := Part^.Next;
end;
if ReloadGeneralInv or not IsMasterGear( M ) then begin
Part := M^.InvCom;
while Part <> Nil do begin
DoReloadMaster( Part , ReloadGeneralInv );
Part := Part^.Next;
end;
end;
end;
Function ReloadCharsCost( GB: GameBoardPtr; PC,NPC: GearPtr; ReloadGeneralInv: Boolean ): LongInt;
{ Calculate the cost of reloading every PC's ammunition. }
var
it: LongInt;
Part: GearPtr;
begin
it := 0;
Part := GB^.Meks;
while Part <> Nil do begin
if ( ( NATtVAlue( Part^.NA , NAG_Location , NAS_Team ) = NAV_DefPlayerTeam ) or ( NAttValue( Part^.NA , NAG_Location , NAS_Team ) = NAV_LancemateTeam ) ) and ( Part^.G = GG_Character ) then begin
it := it + ReloadMasterCost( Part , ReloadGeneralInv );
end;
Part := Part^.Next;
end;
{ SCale the price for the PC's shopping skill. }
if it > 0 then it := ScalePrice( GB , PC , NPC , it );
ReloadCharsCost := it;
end;
Procedure DoReloadChars( GB: GameBoardPtr; PC,NPC: GearPtr; ReloadGeneralInv: Boolean );
{ Calculate the cost of reloading every PC's ammunition. }
var
COst: LongInt;
Part: GearPtr;
begin
Cost := ReloadCharsCost( GB , PC , NPC , ReloadGeneralInv );
if Cost <= NAttValue( PC^.NA , NAG_Experience , NAS_Credits ) then begin
Part := GB^.Meks;
while Part <> Nil do begin
if ( ( NATtVAlue( Part^.NA , NAG_Location , NAS_Team ) = NAV_DefPlayerTeam ) or ( NAttValue( Part^.NA , NAG_Location , NAS_Team ) = NAV_LancemateTeam ) ) and ( Part^.G = GG_Character ) then begin
DoReloadMaster( Part , ReloadGeneralInv );
end;
Part := Part^.Next;
end;
AddNAtt( PC^.NA, NAG_Experience , NAS_Credits , -Cost );
{ Print the message. }
CHAT_Message := MsgString( 'SERVICES_ReloadChars' );
end else begin
{ Player can't afford the reload. }
CHAT_Message := MsgString( 'SERVICES_RALousyBum' );
end;
end;
Function ReloadMechaCost( GB: GameBoardPtr; PC,NPC: GearPtr; ReloadGeneralInv: Boolean ): LongInt;
{ Calculate the cost of reloading every mek's ammunition. }
var
it: LongInt;
Part: GearPtr;
begin
it := 0;
Part := GB^.Meks;
while Part <> Nil do begin
if ( NATtVAlue( Part^.NA , NAG_Location , NAS_Team ) = NAV_DefPlayerTeam ) and ( Part^.G = GG_Mecha ) then begin
it := it + ReloadMasterCost( Part , ReloadGeneralInv );
end;
Part := Part^.Next;
end;
{ SCale the price for the PC's shopping skill. }
if it > 0 then it := ScalePrice( GB , PC , NPC , it );
ReloadMechaCost := it;
end;
Procedure DoReloadMecha( GB: GameBoardPtr; PC,NPC: GearPtr; ReloadGeneralInv: Boolean );
{ Calculate the cost of reloading every PC's ammunition. }
var
COst: LongInt;
Part: GearPtr;
begin
Cost := ReloadMechaCost( GB , PC , NPC , ReloadGeneralInv );
if Cost <= NAttValue( PC^.NA , NAG_Experience , NAS_Credits ) then begin
Part := GB^.Meks;
while Part <> Nil do begin
if ( NATtVAlue( Part^.NA , NAG_Location , NAS_Team ) = NAV_DefPlayerTeam ) and ( Part^.G = GG_Mecha ) then begin
DoReloadMaster( Part , ReloadGeneralInv );
end;
Part := Part^.Next;
end;
AddNAtt( PC^.NA, NAG_Experience , NAS_Credits , -Cost );
{ Print the message. }
CHAT_Message := MsgString( 'SERVICES_ReloadMeks' );
end else begin
{ Player can't afford the reload. }
CHAT_Message := MsgString( 'SERVICES_RALousyBum' );
end;
end;
Function RechargeCost( GB: GameBoardPtr; PC,NPC: GearPtr ): LongInt;
{ Calculate the cost of reloading every PC's ammunition. }
Function RechargeTrackCost( Part: GearPtr ): LongInt;
{ Return the number of spent power points along this track and counting all children. }
var
it: LongInt;
begin
it := 0;