-
Notifications
You must be signed in to change notification settings - Fork 18
/
services.pp
2376 lines (2094 loc) · 74 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. }
{
GearHead: Arena, 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
}
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 }
);
Function Random_Mecha_Colors: String;
Procedure PurchaseGear( GB: GameBoardPtr; PC,NPC,Part: GearPtr );
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 );
Procedure OpenShuttle( GB: GameBoardPtr; PC,NPC: GearPtr );
implementation
{$IFDEF SDLMODE}
uses ability,arenacfe,backpack,damage,gearutil,ghchars,ghmodule,ghparser,
ghswag,ghweapon,interact,menugear,rpgdice,skilluse,texutil,sdlgfx,
sdlinfo,sdlmap,sdlmenus,ui4gh,ghprop;
{$ELSE}
uses ability,arenacfe,backpack,damage,gearutil,ghchars,ghmodule,ghparser,
ghswag,ghweapon,interact,menugear,rpgdice,skilluse,texutil,congfx,
coninfo,conmap,conmenus,context,ui4gh,ghprop;
{$ENDIF}
Const
CredsPerDP = 1; { Cost to repair 1DP of damage. }
MaxShopItems = 21; { Maximum number of items in a shop. }
var
SERV_CUSTOMER: GearPtr;
{$IFDEF SDLMODE}
SERV_GB: GameBoardPtr;
SERV_PC,SERV_NPC,SERV_Info: GearPtr;
SERV_Menu: RPGMenuPtr;
{$ENDIF}
Function ScalePrice( PC,NPC: GearPtr; Price: Int64 ): LongInt;
{ Modify the price listed based upon the PC's shopping skill. }
var
ShopRk,ShopTr,R: Integer; { ShopRank and ShopTarget }
begin
{ Determine the Shopping skill rank of the buyer. }
ShopRk := SkillValue( PC , 21 );
{ 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 := 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;
{ 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 > 40 then ShopRk := 40;
Price := ( Price * (100 - ShopRk ) ) div 100;
end;
if Price < 1 then Price := 1;
ScalePrice := Price;
end;
Function PurchasePrice( 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( PC , NPC , GearValue( 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 := GearValue( Part );
if Price < 1 then Price := 1;
if DoleSkillExperience( PC , 21 , Round( Ln( Price ) ) + 1 ) then begin
DialogMsg( MsgString( 'SHOPPING_SkillAdvance' ) );
end;
end;
{$IFDEF SDLMODE}
Procedure JustGBRedraw;
{ Just redraw the map. }
begin
SDLCombatDisplay( SERV_GB );
end;
Procedure ServiceRedraw;
{ Redraw the screen for whatever service is going to go on. }
begin
SDLCombatDisplay( SERV_GB );
SetupInteractDisplay( TeamColor( SERV_GB , SERV_NPC ) );
DisplayInteractStatus( SERV_GB , SERV_NPC , CHAT_React , CHAT_Endurance );
if SERV_Info <> Nil then begin
{ DisplayGearInfo( SERV_Info , SERV_GB );}
CMessage( SAttValue( SERV_Info^.SA , 'DESC' ) , ZONE_Menu.GetRect() , MenuItem );
end;
CMessage( '$' + BStr( NAttValue( SERV_PC^.NA , NAG_Experience , NAS_Credits ) ) , ZONE_Clock , InfoHilight );
GameMsg( CHAT_Message , ZONE_InteractMsg.GetRect() , InfoHiLight );
end;
Procedure BasicServiceRedraw;
{ Redraw the services interface without any of the bells and whistles. }
begin
SDLCombatDisplay( SERV_GB );
InfoBox( ZONE_ShopTop.GetRect() );
InfoBox( ZONE_ShopBottom.GetRect() );
InfoBox( ZONE_ShopInfo.GetRect() );
InfoBox( ZONE_ShopCash.GetRect() );
DrawPortrait( SERV_GB, SERV_NPC, ZONE_ShopNPCPortrait.GetRect(), False );
DrawPortrait( SERV_GB, SERV_Customer, ZONE_ShopPCPortrait.GetRect(), False );
CMessage( GearName(SERV_NPC) , ZONE_ShopNPCName.GetRect() , InfoHilight );
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 );
end;
Procedure BrowseListRedraw;
{ Redraw the services interface and show the longform info for a list item. }
var
Part: GearPtr;
begin
BasicServiceRedraw();
if ( SERV_Menu <> Nil ) and ( SERV_Info <> Nil ) then begin
Part := RetrieveGearSib( SERV_Info , CurrentMenuItemValue( SERV_Menu ) );
if Part <> Nil then begin
LongformGearInfo( Part , SERV_GB, ZONE_ShopInfo );
end;
end;
end;
Procedure BrowseTreeRedraw;
{ Redraw the services interface and show the longform info for a gear. }
var
Part: GearPtr;
N: Integer;
begin
BasicServiceRedraw();
if ( SERV_Menu <> Nil ) and ( SERV_Info <> Nil ) then begin
N := CurrentMenuItemValue( SERV_Menu );
if N > 0 then begin
Part := LocateGearByNumber( SERV_Info , N );
if Part <> Nil then begin
LongformGearInfo( Part , SERV_GB, ZONE_ShopInfo );
end;
end;
end;
end;
Procedure ShuttleServiceRedraw;
{ Redraw the services interface and show the longform info for a list item. }
var
Part: GearPtr;
begin
BasicServiceRedraw();
if ( SERV_Menu <> Nil ) and ( SERV_Info <> Nil ) then begin
Part := FindActualScene( SERV_GB , CurrentMenuItemValue( SERV_Menu ) );
if Part <> Nil then begin
LongformGearInfo( Part , SERV_GB, ZONE_ShopInfo );
end;
end;
end;
Procedure FocusOnOneRedraw;
{ Redraw the services interface and show the longform info for a list item. }
begin
BasicServiceRedraw();
if ( SERV_Info <> Nil ) then begin
LongformGearInfo( SERV_Info , SERV_GB, ZONE_ShopInfo );
end;
end;
{$ENDIF}
procedure BuyAmmoClips( GB: GameBoardPtr; PC,NPC,Weapon: GearPtr );
{ Allow spare clips to be purchased for this weapon. }
var
AmmoList: GearPtr;
Procedure AddAmmoToList( Proto: GearPtr );
{ Create a clone of this ammunition and add it to the list. }
var
A,ATmp,AVar,VarList: GearPtr;
begin
A := CloneGear( Proto );
AppendGear( AmmoList , A );
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;
LookForAmmo( Weapon^.SubCom );
{ Step Two: Create the shopping menu. }
{$IFDEF SDLMODE}
ShopMenu := CreateRPGMenu( MenuItem , MenuSelect , ZONE_ShopMenu );
{$ELSE}
ShopMenu := CreateRPGMenu( MenuItem , MenuSelect , ZONE_InteractMenu );
{$ENDIF}
N := 1;
Ammo := AmmoList;
while Ammo <> Nil do begin
AddRPGMenuItem( ShopMenu , GearName( Ammo ) + ' ($' + BStr( PurchasePrice( 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_Customer := PC;
{$IFDEF SDLMODE}
SERV_GB := GB;
SERV_PC := PC;
SERV_NPC := NPC;
SERV_Info := AmmoList;
SERV_Menu := ShopMenu;
N := SelectMenu( ShopMenu , @BrowseListRedraw );
{$ELSE}
N := SelectMenu( ShopMenu );
{$ENDIF}
if N > 0 then begin
Ammo := RetrieveGearSib( AmmoList , N );
Cost := PurchasePrice( 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 );
{$IFDEF SDLMODE}
CHAT_Message := MsgString( 'BUYREPLY' + BStr( Random( 4 ) + 1 ) );
{$ELSE}
GameMsg( MsgString( 'BUYREPLY' + BStr( Random( 4 ) + 1 ) ) , ZONE_InteractMsg , InfoHilight );
{$ENDIF}
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 ) ) );
{$IFDEF SDLMODE}
Chat_Message := MsgString( 'BUYNOCASH' + BStr( Random( 4 ) + 1 ) );
{$ELSE}
GameMsg( MsgString( 'BUYNOCASH' + BStr( Random( 4 ) + 1 ) ) , ZONE_InteractMsg , InfoHiLight );
{$ENDIF}
end;
end;
until N = -1;
{ Upon exiting, dispose of the ammo list. }
DisposeRPGMenu( ShopMenu );
DisposeGear( AmmoList );
end;
procedure PurchaseGear( GB: GameBoardPtr; PC,NPC,Part: GearPtr );
{ The unit 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. }
var
YNMenu: RPGMenuPtr;
Cost: LongInt;
N: Integer;
msg: String;
begin
Cost := PurchasePrice( PC , NPC , Part );
{$IFDEF SDLMODE}
YNMenu := CreateRPGMenu( MenuItem , MenuSelect , ZONE_ShopMenu );
{$ELSE}
YNMenu := CreateRPGMenu( MenuItem , MenuSelect , ZONE_InteractMenu );
{$ENDIF}
AddRPGMenuItem( YNMenu , 'Buy ' + GearName( Part ) + ' ($' + BStr( Cost ) + ')' , 1 );
if ( Part^.G = GG_Mecha ) then AddRPGMenuItem( YNMenu , 'View Tech Stats' , 3 );
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' ) , 4 );
AddRPGMenuItem( YNMenu , 'Search Again' , -1 );
msg := MSgString( 'BuyPROMPT' + Bstr( Random( 4 ) + 1 ) );
msg := ReplaceHash( msg , GearName( Part ) );
msg := ReplaceHash( msg , BStr( Cost ) );
{$IFDEF SDLMODE}
CHAT_Message := Msg;
{$ELSE}
GameMsg( msg , ZONE_InteractMsg , InfoHilight );
{$ENDIF}
repeat
SERV_Customer := PC;
{$IFDEF SDLMODE}
SERV_GB := GB;
SERV_PC := PC;
SERV_NPC := NPC;
SERV_Info := Part;
N := SelectMenu( YNMenu , @FocusOnOneRedraw );
{$ELSE}
DisplayGearInfo( Part );
CMessage( '$' + BStr( NAttValue( PC^.NA , NAG_Experience , NAS_Credits ) ) , ZONE_Clock , InfoHilight );
N := SelectMenu( YNMenu );
{$ENDIF}
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 );
{$IFDEF SDLMODE}
CHAT_Message := MsgString( 'BUYREPLY' + BStr( Random( 4 ) + 1 ) );
{$ELSE}
GameMsg( MsgString( 'BUYREPLY' + BStr( Random( 4 ) + 1 ) ) , ZONE_InteractMsg , InfoHilight );
{$ENDIF}
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 ) ) );
{$IFDEF SDLMODE}
CHAT_Message := MsgString( 'BUYNOCASH' + BStr( Random( 4 ) + 1 ) );
{$ELSE}
GameMsg( MsgString( 'BUYNOCASH' + BStr( Random( 4 ) + 1 ) ) , ZONE_InteractMsg , InfoHilight );
{$ENDIF}
end;
end else if N = 2 then begin
{$IFDEF SDLMODE}
MechaPartBrowser( Part , @JustGBRedraw );
{$ELSE}
MechaPartBrowser( Part );
{$ENDIF}
end else if N = 3 then begin
{$IFDEF SDLMODE}
CHAT_Message := MechaDescription( Part );
{$ELSE}
GameMsg( MechaDescription( Part ) , ZONE_MEnu , InfoGreen );
EndOfGameMoreKey;
{$ENDIF}
N := 2;
end else if N = 4 then begin
BuyAmmoClips( GB, PC, NPC, Part )
end else if N = -1 then begin
{$IFDEF SDLMODE}
CHAT_Message := MsgString( 'BUYCANCEL' + BStr( Random( 4 ) + 1 ) );
{$ELSE}
GameMsg( MsgString( 'BUYCANCEL' + BStr( Random( 4 ) + 1 ) ) , ZONE_InteractMsg , InfoHilight );
{$ENDIF}
end;
until N <> 2;
DisposeRPGMenu( YNMenu );
end;
Function SellGear( var LList,Part: GearPtr; PC,NPC: GearPtr ): 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. }
{ NOTE: SERV_GB must be set before this proc is called!!! }
const
V_MAX = 2147483647;
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 := AStringHasBString( SAttValue( Part^.SA , 'TYPE' ) , 'STOLEN' ) and ( NPC <> Nil ) and ( NPC^.G = GG_Character );
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. }
{$IFDEF SDLMODE}
CHAT_Message := MsgString( 'SERVICES_StolenResponse' );
{$ELSE}
GameMsg( MsgString( 'SERVICES_StolenResponse' ) , ZONE_InteractMsg , EnemyRed );
{$ENDIF}
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 := BaseGearValue( Part );
if Destroyed( Part ) then Cost := Cost div 3;
{ Determine shopping rank. }
ShopRk := SkillValue( PC , 21 );
{ 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 (V_MAX < Cost) then begin
Cost := V_MAX;
end else if (Cost < 1) then begin
Cost := 1;
end;
{$IFDEF SDLMODE}
YNMenu := CreateRPGMenu( MenuItem , MenuSelect , ZONE_ShopMenu );
{$ELSE}
YNMenu := CreateRPGMenu( MenuItem , MenuSelect , ZONE_InteractMenu );
{$ENDIF}
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 ) );
SERV_Customer := PC;
{$IFDEF SDLMODE}
SERV_PC := PC;
SERV_NPC := NPC;
SERV_Info := Part;
CHAT_Message := Msg;
N := SelectMenu( YNMenu , @FocusOnOneRedraw );
{$ELSE}
GameMsg( msg , ZONE_InteractMsg , InfoHilight );
N := SelectMenu( YNMenu );
{$ENDIF}
if N = 1 then begin
{ Increase the buyer's cash by the price of the gear. }
AddNAtt( PC^.NA , NAG_Experience , NAS_Credits , Cost );
{$IFDEF SDLMODE}
CHAT_Message := MSgString( 'SELLREPLY' + Bstr( Random( 4 ) + 1 ) );
{$ELSE}
GameMsg( MSgString( 'SELLREPLY' + Bstr( Random( 4 ) + 1 ) ) , ZONE_InteractMsg , InfoHilight );
{$ENDIF}
msg := MSgString( 'SELL_YOUHAVESOLD' );
msg := ReplaceHash( msg , GearName( Part ) );
msg := ReplaceHash( msg , BStr( Cost ) );
DialogMSG( msg );
{ Give some XP to the PC's SHOPPING skill. }
ShoppingXP( PC , Part );
{ 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
{$IFDEF SDLMODE}
CHAT_Message := MSgString( 'SELLCANCEL' + Bstr( Random( 4 ) + 1 ) );
{$ELSE}
GameMsg( MSgString( 'SELLCANCEL' + Bstr( Random( 4 ) + 1 ) ) , ZONE_InteractMsg , InfoHilight );
{$ENDIF}
end;
DisposeRPGMenu( YNMenu );
SellGear := N = 1;
end;
Function RepairMasterCost( Master: GearPtr; Skill: Integer ): LongInt;
{ Return the expected cost of repairing every component of }
{ MASTER which can be handled using SKILL. }
const
it_MAX = 2147483647;
var
it: Int64;
begin
it := Int64(TotalRepairableDamage( Master , SKill )) * Int64(CredsPerDP);
{ Since parts that could be helped by First Aid heal by themselves }
{ usually, the cost to treat injuries using the First Aid skill is }
{ substantially reduced. }
if ( Skill = 20 ) and ( it > 0 ) then begin
it := it div 2;
if it < 1 then it := 1;
end;
if it < 0 then begin
it := 0;
end else if it_MAX < it then begin
it := it_MAX;
end;
RepairMasterCost := it;
end;
Function RepairAllCost( GB: GameBoardPtr; Skill: 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 + RepairMasterCost( Part , Skill );
end;
end;
Part := Part^.Next;
end;
RepairAllCost := Cost;
end;
Procedure DoRepairMaster( GB: GameBoardPtr; Master,Repairer: GearPtr; Skill: 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 , SKill );
ApplyRepairPoints( Master , Skill , TRD );
{ Wait an amount of time, depending on the repairer's skill }
{ level. }
QuickTime( GB , AP_Minute + RollStep( 12 ) - SkillValue( Repairer , SKill ) );
end;
Procedure DoRepairAll( GB: GameBoardPtr; NPC: GearPtr; Skill: 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
DoRepairMaster( GB , Part , NPC , Skill );
end;
end;
Part := Part^.Next;
end;
end;
Procedure RepairAllFrontEnd( GB: GameBoardPtr; PC, NPC: GearPtr; Skill: 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( PC , NPC , RepairAllCost( GB , Skill ) );
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( 150 ) + 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 , Skill );
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;
{$IFDEF SDLMODE}
CHAT_Message := msg;
{$ELSE}
GameMsg( msg , ZONE_InteractMsg , InfoHiLight );
{$ENDIF}
end;
Procedure RepairOneFrontEnd( GB: GameBoardPtr; Part, PC, NPC: GearPtr; Skill: 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( PC , NPC , RepairMasterCost( PArt , Skill ) );
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. }
{$IFDEF SDLMODE}
CHAT_Message := SAttValue( TEXT_MESSAGES , 'SERVICES_RAFree' );
{$ELSE}
GameMsg( SAttValue( TEXT_MESSAGES , 'SERVICES_RAFree' ) , ZONE_InteractMsg , InfoHiLight );
{$ENDIF}
Cost := 0;
end else if ( Cash < Cost ) and ( R > 10 ) then begin
{$IFDEF SDLMODE}
CHAT_Message := SAttValue( TEXT_MESSAGES , 'SERVICES_RACantPay' );
{$ELSE}
GameMsg( SAttValue( TEXT_MESSAGES , 'SERVICES_RACantPay' ) , ZONE_InteractMsg , InfoHiLight );
{$ENDIF}
AddNAtt( PC^.NA , NAG_ReactionScore , NAttValue( NPC^.NA , NAG_Personal , NAS_CID ) , -Random( 5 ) );
Cost := 0;
end;
if Cost < Cash then begin
DoRepairMaster( GB , Part , NPC , Skill );
AddNAtt( PC^.NA, NAG_Experience , NAS_Credits , -Cost );
{$IFDEF SDLMODE}
CHAT_Message := SAttValue( TEXT_MESSAGES , 'SERVICES_RADoRA' + BStr( Random( NumRepairSayings ) + 1 ) );
{$ELSE}
GameMsg( SAttValue( TEXT_MESSAGES , 'SERVICES_RADoRA' + BStr( Random( NumRepairSayings ) + 1 ) ) , ZONE_InteractMsg , InfoHiLight );
{$ENDIF}
end else begin
{$IFDEF SDLMODE}
CHAT_Message := SAttValue( TEXT_MESSAGES , 'SERVICES_RALousyBum' );
{$ELSE}
GameMsg( SAttValue( TEXT_MESSAGES , 'SERVICES_RALousyBum' ) , ZONE_InteractMsg , InfoHiLight );
{$ENDIF}
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 := ( BaseAmmoValue( Mag ) * Spent ) div Mag^.Stat[ STAT_AmmoPresent ];
if it < 1 then it := 1;
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 ): 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 );
Part := Part^.Next;
end;
Part := M^.InvCom;
while Part <> Nil do begin
it := it + ReloadMasterCost( Part );
Part := Part^.Next;
end;
ReloadMasterCost := it;
end;
Procedure DoReloadMaster( M: GearPtr );
{ 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 );
Part := Part^.Next;
end;
Part := M^.InvCom;
while Part <> Nil do begin
DoReloadMaster( Part );
Part := Part^.Next;
end;
end;
Function ReloadCharsCost( GB: GameBoardPtr; PC,NPC: GearPtr ): 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 );
end;
Part := Part^.Next;
end;
{ SCale the price for the PC's shopping skill. }
if it > 0 then it := ScalePrice( PC , NPC , it );
ReloadCharsCost := it;
end;
Procedure DoReloadChars( GB: GameBoardPtr; PC,NPC: GearPtr );
{ Calculate the cost of reloading every PC's ammunition. }
var
COst: LongInt;
Part: GearPtr;
begin
Cost := ReloadCharsCost( GB , PC , NPC );
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 );
end;
Part := Part^.Next;
end;
{ Print the message. }
{$IFDEF SDLMODE}
CHAT_Message := SAttValue( TEXT_MESSAGES , 'SERVICES_ReloadChars' );
{$ELSE}
GameMsg( SAttValue( TEXT_MESSAGES , 'SERVICES_ReloadChars' ) , ZONE_InteractMsg , InfoHiLight );
{$ENDIF}
end else begin
{ Player can't afford the reload. }
{$IFDEF SDLMODE}
CHAT_Message := SAttValue( TEXT_MESSAGES , 'SERVICES_RALousyBum' );
{$ELSE}
GameMsg( SAttValue( TEXT_MESSAGES , 'SERVICES_RALousyBum' ) , ZONE_InteractMsg , InfoHiLight );
{$ENDIF}
end;
end;
Function ReloadMechaCost( GB: GameBoardPtr; PC,NPC: GearPtr ): 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 );
end;
Part := Part^.Next;
end;
{ SCale the price for the PC's shopping skill. }
if it > 0 then it := ScalePrice( PC , NPC , it );
ReloadMechaCost := it;
end;
Procedure DoReloadMecha( GB: GameBoardPtr; PC,NPC: GearPtr );
{ Calculate the cost of reloading every PC's ammunition. }
var
COst: LongInt;
Part: GearPtr;
begin
Cost := ReloadMechaCost( GB , PC , NPC );
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 );
end;
Part := Part^.Next;
end;
{ Print the message. }
{$IFDEF SDLMODE}
CHAT_Message := SAttValue( TEXT_MESSAGES , 'SERVICES_ReloadMeks' );
{$ELSE}
GameMsg( SAttValue( TEXT_MESSAGES , 'SERVICES_ReloadMeks' ) , ZONE_InteractMsg , InfoHiLight );
{$ENDIF}
end else begin
{ Player can't afford the reload. }
{$IFDEF SDLMODE}
CHAT_Message := SAttValue( TEXT_MESSAGES , 'SERVICES_RALousyBum' );
{$ELSE}
GameMsg( SAttValue( TEXT_MESSAGES , 'SERVICES_RALousyBum' ) , ZONE_InteractMsg , InfoHiLight );
{$ENDIF}
end;
end;
Function NotGoodWares( I , NPC: GearPtr; Stuff: String ): Boolean;
{ Return TRUE if this item is inappropriate for NPC's shop, }
{ FALSE if it is. An item is appropriate if: }
{ - its G value may be found in STUFF. }
{ - its unscaled value doesn't exceed the shopkeep's rating. }
var
NGW: Boolean;
N: Integer;
Cost: LongInt;
begin
{ Begin by assuming TRUE. }
NGW := True;
{ Search through STUFF to see if Item's general type is listed. }
while Stuff <> '' do begin
N := ExtractValue( Stuff );
if I^.G = N then NGW := False;
end;
if not NGW then begin
{ Determine the unscaled cost of this item. }
Cost := GearValue( I );
N := I^.Scale;
while N > 0 do begin
Dec( N );
Cost := Cost div 5;
end;
{ Determine the Log base 2 of the item... this will be }
{ the target number to decide whether or not the shopkeep }
{ might have this item. }
N := 0;
while Cost > 2 do begin
Inc( N );
Cost := Cost div 2;
end;
if RollStep( SkillValue( NPC , 21 ) ) < N then NGW := True;
end;
NotGoodWares := NGW;
end;
Procedure AddAmmo( var Wares: GearPtr; Part: GearPtr );
{ Browse through PART. If you find any guns or missile launchers, }
{ clone its ammunition & add it to WARES. }
var
A,A2: GearPtr;
begin
while Part <> Nil do begin