-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.cs
4209 lines (3717 loc) · 141 KB
/
Game.cs
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
/*******************************************************************************
*
* Space Trader for Windows 1.00
*
* Copyright (C) 2016 Keith Banner, All Rights Reserved
*
* Port to Windows by David Pierron & Jay French
* Original coding by Pieter Spronck, Sam Anderson, Samuel Goldstein, Matt Lee
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option) any
* later version.
*
* This program 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 General Public License for more details.
*
* If you'd like a copy of the GNU General Public License, go to
* http://www.gnu.org/copyleft/gpl.html.
*
* You can contact the author at [email protected]
*
******************************************************************************/
using System;
using System.Collections;
using System.Windows.Forms;
namespace SpaceTrader
{
public class Game : STSerializableObject
{
#region Member Declarations
private static Game _game;
// Game Data
private StarSystem[] _universe;
private int[] _wormholes = new int[6];
private CrewMember[] _mercenaries = new CrewMember[Strings.CrewMemberNames.Length];
private Commander _commander;
private Ship _dragonfly = new Ship(ShipType.Dragonfly);
private Ship _scarab = new Ship(ShipType.Scarab);
private Ship _scorpion = new Ship(ShipType.Scorpion);
private Ship _spaceMonster = new Ship(ShipType.SpaceMonster);
private Ship _opponent = new Ship(ShipType.Gnat);
private int _chanceOfTradeInOrbit = 100;
private int _clicks = 0; // Distance from target system, 0 = arrived
private bool _raided = false; // True when the commander has been raided during the trip
private bool _inspected = false; // True when the commander has been inspected during the trip
private bool _tribbleMessage = false; // Is true if the Ship Yard on the current system informed you about the tribbles
private bool _arrivedViaWormhole = false; // flag to indicate whether player arrived on current planet via wormhole
private bool _paidForNewspaper = false; // once you buy a paper on a system, you don't have to pay again.
private bool _litterWarning = false; // Warning against littering has been issued.
private ArrayList _newsEvents = new ArrayList(30);
// Current Selections
private Difficulty _difficulty = Difficulty.Normal; // Difficulty level
private bool _cheatEnabled = false;
private bool _autoSave = false;
private bool _easyEncounters = false;
private GameEndType _endStatus = GameEndType.Na;
private EncounterType _encounterType = 0; // Type of current encounter
private StarSystemId _selectedSystemId = StarSystemId.Na; // Current system on chart
private StarSystemId _warpSystemId = StarSystemId.Na; // Target system for warp
private StarSystemId _trackedSystemId = StarSystemId.Na; // The short-range chart will display an arrow towards this system if the value is not null
private bool _targetWormhole = false; // Wormhole selected?
private int[] _priceCargoBuy = new int[10];
private int[] _priceCargoSell = new int[10];
// Status of Quests
private int _questStatusArtifact = 0; // 0 = not given yet, 1 = Artifact on board, 2 = Artifact no longer on board (either delivered or lost)
private int _questStatusDragonfly = 0; // 0 = not available, 1 = Go to Baratas, 2 = Go to Melina, 3 = Go to Regulas, 4 = Go to Zalkon, 5 = Dragonfly destroyed, 6 = Got Shield
private int _questStatusExperiment = 0; // 0 = not given yet, 1-11 = days from start; 12 = performed, 13 = canceled
private int _questStatusGemulon = 0; // 0 = not given yet, 1-7 = days from start, 8 = too late, 9 = in time, 10 = done
private int _questStatusJapori = 0; // 0 = no disease, 1 = Go to Japori (always at least 10 medicine cannisters), 2 = Assignment finished or canceled
private int _questStatusJarek = 0; // 0 = not delivered, 1-11 = on board, 12 = delivered
private int _questStatusMoon = 0; // 0 = not bought, 1 = bought, 2 = claimed
private int _questStatusPrincess = 0; // 0 = not available, 1 = Go to Centauri, 2 = Go to Inthara, 3 = Go to Qonos, 4 = Princess Rescued, 5-14 = On Board, 15 = Princess Returned, 16 = Got Quantum Disruptor
private int _questStatusReactor = 0; // 0 = not encountered, 1-20 = days of mission (bays of fuel left = 10 - (ReactorStatus / 2), 21 = delivered, 22 = Done
private int _questStatusScarab = 0; // 0 = not given yet, 1 = not destroyed, 2 = destroyed - upgrade not performed, 3 = destroyed - hull upgrade performed
private int _questStatusSculpture = 0; // 0 = not given yet, 1 = on board, 2 = delivered, 3 = done
private int _questStatusSpaceMonster = 0; // 0 = not available, 1 = Space monster is in Acamar system, 2 = Space monster is destroyed, 3 = Claimed reward
private int _questStatusWild = 0; // 0 = not delivered, 1-11 = on board, 12 = delivered
private int _fabricRipProbability = 0; // if Experiment = 12, this is the probability of being warped to a random planet.
private bool _justLootedMarie = false; // flag to indicate whether player looted Marie Celeste
private bool _canSuperWarp = false; // Do you have the Portable Singularity on board?
private int _chanceOfVeryRareEncounter = 5;
private ArrayList _veryRareEncounters = new ArrayList(6); // Array of Very Rare encounters not done yet.
// Options
private GameOptions _options = new GameOptions(true);
// The rest of the member variables are not saved between games.
private bool _encounterCmdrFleeing = false;
private bool _encounterCmdrHit = false;
#endregion
#region Methods
public Game(string name, Difficulty difficulty, int pilot, int fighter, int trader, int engineer, SpaceTrader parentWin)
{
_game = this;
ParentWindow = parentWin;
_difficulty = difficulty;
// Keep Generating a new universe until PlaceSpecialEvents and PlaceShipyards return true,
// indicating all special events and shipyards were placed.
do
GenerateUniverse();
while (!(PlaceSpecialEvents() && PlaceShipyards()));
InitializeCommander(name, new CrewMember(CrewMemberId.Commander, pilot, fighter, trader, engineer, StarSystemId.Na));
GenerateCrewMemberList();
CreateShips();
CalculatePrices(Commander.CurrentSystem);
ResetVeryRareEncounters();
if (Difficulty < Difficulty.Normal)
Commander.CurrentSystem.SpecialEventType = SpecialEventType.Lottery;
// TODO: JAF - DEBUG
/*
Commander.Cash = 1000000;
CheatEnabled = true;
EasyEncounters = true;
*/
}
public Game(Hashtable hash, SpaceTrader parentWin) : base(hash)
{
_game = this;
ParentWindow = parentWin;
string version = (string)GetValueFromHash(hash, "_version");
if (version.CompareTo(Consts.CurrentVersion) > 0)
throw new FutureVersionException();
_universe = (StarSystem[])ArrayListToArray((ArrayList)GetValueFromHash(hash, "_universe"), "StarSystem");
_wormholes = (int[])GetValueFromHash(hash, "_wormholes", _wormholes);
_mercenaries = (CrewMember[])ArrayListToArray((ArrayList)GetValueFromHash(hash, "_mercenaries"), "CrewMember");
_commander = new Commander((Hashtable)GetValueFromHash(hash, "_commander"));
_dragonfly = new Ship((Hashtable)GetValueFromHash(hash, "_dragonfly", _dragonfly.Serialize()));
_scarab = new Ship((Hashtable)GetValueFromHash(hash, "_scarab", _scarab.Serialize()));
_scorpion = new Ship((Hashtable)GetValueFromHash(hash, "_scorpion", _scorpion.Serialize()));
_spaceMonster = new Ship((Hashtable)GetValueFromHash(hash, "_spaceMonster", _spaceMonster.Serialize()));
_opponent = new Ship((Hashtable)GetValueFromHash(hash, "_opponent", _opponent.Serialize()));
_chanceOfTradeInOrbit = (int)GetValueFromHash(hash, "_chanceOfTradeInOrbit", _chanceOfTradeInOrbit);
_clicks = (int)GetValueFromHash(hash, "_clicks", _clicks);
_raided = (bool)GetValueFromHash(hash, "_raided", _raided);
_inspected = (bool)GetValueFromHash(hash, "_inspected", _inspected);
_tribbleMessage = (bool)GetValueFromHash(hash, "_tribbleMessage", _tribbleMessage);
_arrivedViaWormhole = (bool)GetValueFromHash(hash, "_arrivedViaWormhole", _arrivedViaWormhole);
_paidForNewspaper = (bool)GetValueFromHash(hash, "_paidForNewspaper", _paidForNewspaper);
_litterWarning = (bool)GetValueFromHash(hash, "_litterWarning", _litterWarning);
_newsEvents = new ArrayList((int[])GetValueFromHash(hash, "_newsEvents", _newsEvents.ToArray(System.Type.GetType("System.Int32"))));
_difficulty = (Difficulty)GetValueFromHash(hash, "_difficulty", _difficulty);
_cheatEnabled = (bool)GetValueFromHash(hash, "_cheatEnabled", _cheatEnabled);
_autoSave = (bool)GetValueFromHash(hash, "_autoSave", _autoSave);
_easyEncounters = (bool)GetValueFromHash(hash, "_easyEncounters", _easyEncounters);
_endStatus = (GameEndType)GetValueFromHash(hash, "_endStatus", _endStatus);
_encounterType = (EncounterType)GetValueFromHash(hash, "_encounterType", _encounterType);
_selectedSystemId = (StarSystemId)GetValueFromHash(hash, "_selectedSystemId", _selectedSystemId);
_warpSystemId = (StarSystemId)GetValueFromHash(hash, "_warpSystemId", _warpSystemId);
_trackedSystemId = (StarSystemId)GetValueFromHash(hash, "_trackedSystemId", _trackedSystemId);
_targetWormhole = (bool)GetValueFromHash(hash, "_targetWormhole", _targetWormhole);
_priceCargoBuy = (int[])GetValueFromHash(hash, "_priceCargoBuy", _priceCargoBuy);
_priceCargoSell = (int[])GetValueFromHash(hash, "_priceCargoSell", _priceCargoSell);
_questStatusArtifact = (int)GetValueFromHash(hash, "_questStatusArtifact", _questStatusArtifact);
_questStatusDragonfly = (int)GetValueFromHash(hash, "_questStatusDragonfly", _questStatusDragonfly);
_questStatusExperiment = (int)GetValueFromHash(hash, "_questStatusExperiment", _questStatusExperiment);
_questStatusGemulon = (int)GetValueFromHash(hash, "_questStatusGemulon", _questStatusGemulon);
_questStatusJapori = (int)GetValueFromHash(hash, "_questStatusJapori", _questStatusJapori);
_questStatusJarek = (int)GetValueFromHash(hash, "_questStatusJarek", _questStatusJarek);
_questStatusMoon = (int)GetValueFromHash(hash, "_questStatusMoon", _questStatusMoon);
_questStatusPrincess = (int)GetValueFromHash(hash, "_questStatusPrincess", _questStatusPrincess);
_questStatusReactor = (int)GetValueFromHash(hash, "_questStatusReactor", _questStatusReactor);
_questStatusScarab = (int)GetValueFromHash(hash, "_questStatusScarab", _questStatusScarab);
_questStatusSculpture = (int)GetValueFromHash(hash, "_questStatusSculpture", _questStatusSculpture);
_questStatusSpaceMonster = (int)GetValueFromHash(hash, "_questStatusSpaceMonster", _questStatusSpaceMonster);
_questStatusWild = (int)GetValueFromHash(hash, "_questStatusWild", _questStatusWild);
_fabricRipProbability = (int)GetValueFromHash(hash, "_fabricRipProbability", _fabricRipProbability);
_justLootedMarie = (bool)GetValueFromHash(hash, "_justLootedMarie", _justLootedMarie);
_canSuperWarp = (bool)GetValueFromHash(hash, "_canSuperWarp", _canSuperWarp);
_chanceOfVeryRareEncounter = (int)GetValueFromHash(hash, "_chanceOfVeryRareEncounter", _chanceOfVeryRareEncounter);
_veryRareEncounters = new ArrayList((int[])GetValueFromHash(hash, "_veryRareEncounters", _veryRareEncounters.ToArray(System.Type.GetType("System.Int32"))));
_options = new GameOptions((Hashtable)GetValueFromHash(hash, "_options", _options.Serialize()));
}
public void Arrested()
{
int term = Math.Max(30, -Commander.PoliceRecordScore);
int fine = (1 + Commander.Worth * Math.Min(80, -Commander.PoliceRecordScore) / 50000) * 500;
if (Commander.Ship.WildOnBoard)
fine = (int)(fine * 1.05);
FormAlert.Alert(AlertType.EncounterArrested, ParentWindow);
FormAlert.Alert(AlertType.JailConvicted, ParentWindow, Functions.Multiples(term, Strings.TimeUnit),
Functions.Multiples(fine, Strings.MoneyUnit));
if (Commander.Ship.HasGadget(GadgetType.HiddenCargoBays))
{
while (Commander.Ship.HasGadget(GadgetType.HiddenCargoBays))
Commander.Ship.RemoveEquipment(EquipmentType.Gadget, GadgetType.HiddenCargoBays);
FormAlert.Alert(AlertType.JailHiddenCargoBaysRemoved, ParentWindow);
}
if (Commander.Ship.ReactorOnBoard)
{
FormAlert.Alert(AlertType.ReactorConfiscated, ParentWindow);
QuestStatusReactor = SpecialEvent.StatusReactorNotStarted;
}
if (Commander.Ship.SculptureOnBoard)
{
FormAlert.Alert(AlertType.SculptureConfiscated, ParentWindow);
QuestStatusSculpture = SpecialEvent.StatusSculptureNotStarted;
}
if (Commander.Ship.WildOnBoard)
{
FormAlert.Alert(AlertType.WildArrested, ParentWindow);
NewsAddEvent(NewsEvent.WildArrested);
QuestStatusWild = SpecialEvent.StatusWildNotStarted;
}
if (Commander.Ship.AnyIllegalCargo)
{
FormAlert.Alert(AlertType.JailIllegalGoodsImpounded, ParentWindow);
Commander.Ship.RemoveIllegalGoods();
}
if (Commander.Insurance)
{
FormAlert.Alert(AlertType.JailInsuranceLost, ParentWindow);
Commander.Insurance = false;
Commander.NoClaim = 0;
}
if (Commander.Ship.CrewCount - Commander.Ship.SpecialCrew.Length > 1)
{
FormAlert.Alert(AlertType.JailMercenariesLeave, ParentWindow);
for (int i = 1; i < Commander.Ship.Crew.Length; i++)
Commander.Ship.Crew[i] = null;
}
if (Commander.Ship.JarekOnBoard)
{
FormAlert.Alert(AlertType.JarekTakenHome, ParentWindow);
QuestStatusJarek = SpecialEvent.StatusJarekNotStarted;
}
if (Commander.Ship.PrincessOnBoard)
{
FormAlert.Alert(AlertType.PrincessTakenHome, ParentWindow);
QuestStatusPrincess = SpecialEvent.StatusPrincessNotStarted;
}
if (QuestStatusJapori == SpecialEvent.StatusJaporiInTransit)
{
FormAlert.Alert(AlertType.AntidoteTaken, ParentWindow);
QuestStatusJapori = SpecialEvent.StatusJaporiDone;
}
if (Commander.Cash >= fine)
Commander.Cash -= fine;
else
{
Commander.Cash = Math.Max(0, Commander.Cash + Commander.Ship.Worth(true) - fine);
FormAlert.Alert(AlertType.JailShipSold, ParentWindow);
if (Commander.Ship.Tribbles > 0)
FormAlert.Alert(AlertType.TribblesRemoved, ParentWindow);
FormAlert.Alert(AlertType.FleaBuilt, ParentWindow);
CreateFlea();
}
if (Commander.Debt > 0)
{
int paydown = Math.Min(Commander.Cash, Commander.Debt);
Commander.Debt -= paydown;
Commander.Cash -= paydown;
if (Commander.Debt > 0)
for (int i = 0; i < term; i++)
Commander.PayInterest();
}
Commander.PoliceRecordScore = Consts.PoliceRecordScoreDubious;
IncDays(term, ParentWindow);
}
private void Arrival()
{
Commander.CurrentSystem = WarpSystem;
Commander.CurrentSystem.Visited = true;
PaidForNewspaper = false;
if (TrackedSystem == Commander.CurrentSystem && Options.TrackAutoOff)
TrackedSystemId = StarSystemId.Na;
ArrivalCheckReactor();
ArrivalCheckTribbles();
ArrivalCheckDebt();
ArrivalPerformRepairs();
ArrivalUpdatePressuresAndQuantities();
ArrivalCheckEasterEgg();
CalculatePrices(Commander.CurrentSystem);
NewsAddEventsOnArrival();
if (Options.NewsAutoShow)
ShowNewspaper();
}
private void ArrivalCheckDebt()
{
// Check for Large Debt - 06/30/01 SRA
if (Commander.Debt >= Consts.DebtWarning)
FormAlert.Alert(AlertType.DebtWarning, ParentWindow);
// Debt Reminder
else if (Commander.Debt > 0 && Options.RemindLoans && Commander.Days % 5 == 0)
FormAlert.Alert(AlertType.DebtReminder, ParentWindow, Functions.Multiples(Commander.Debt, Strings.MoneyUnit));
}
private void ArrivalCheckEasterEgg()
{
/* This Easter Egg gives the commander a Lighting Shield */
if (Commander.CurrentSystem.Id == StarSystemId.Og)
{
bool egg = true;
for (int i = 0; i < Commander.Ship.Cargo.Length && egg; i++)
if (Commander.Ship.Cargo[i] != 1)
egg = false;
if (egg && Commander.Ship.FreeSlotsShield > 0)
{
FormAlert.Alert(AlertType.Egg, ParentWindow);
Commander.Ship.AddEquipment(Consts.Shields[(int)ShieldType.Lightning]);
for (int i = 0; i < Commander.Ship.Cargo.Length; i++)
{
Commander.Ship.Cargo[i] = 0;
Commander.PriceCargo[i] = 0;
}
}
}
}
private void ArrivalCheckReactor()
{
if (QuestStatusReactor == SpecialEvent.StatusReactorDate)
{
FormAlert.Alert(AlertType.ReactorMeltdown, ParentWindow);
QuestStatusReactor = SpecialEvent.StatusReactorNotStarted;
if (Commander.Ship.EscapePod)
EscapeWithPod();
else
{
FormAlert.Alert(AlertType.ReactorDestroyed, ParentWindow);
throw new GameEndException(GameEndType.Killed);
}
}
else
{
// Reactor warnings:
// now they know the quest has a time constraint!
if (QuestStatusReactor == SpecialEvent.StatusReactorFuelOk + 1)
FormAlert.Alert(AlertType.ReactorWarningFuel, ParentWindow);
// better deliver it soon!
else if (QuestStatusReactor == SpecialEvent.StatusReactorDate - 4)
FormAlert.Alert(AlertType.ReactorWarningFuelGone, ParentWindow);
// last warning!
else if (QuestStatusReactor == SpecialEvent.StatusReactorDate - 2)
FormAlert.Alert(AlertType.ReactorWarningTemp, ParentWindow);
}
}
private void ArrivalCheckTribbles()
{
Ship ship = Commander.Ship;
if (ship.Tribbles > 0)
{
int previousTribbles = ship.Tribbles;
int narc = (int)TradeItemType.Narcotics;
int food = (int)TradeItemType.Food;
if (ship.ReactorOnBoard)
{
if (ship.Tribbles < 20)
{
ship.Tribbles = 0;
FormAlert.Alert(AlertType.TribblesAllDied, ParentWindow);
}
else
{
ship.Tribbles /= 2;
FormAlert.Alert(AlertType.TribblesHalfDied, ParentWindow);
}
}
else if (ship.Cargo[narc] > 0)
{
int dead = Math.Min(1 + Functions.GetRandom(3), ship.Cargo[narc]);
Commander.PriceCargo[narc] = Commander.PriceCargo[narc] * (ship.Cargo[narc] - dead) / ship.Cargo[narc];
ship.Cargo[narc] -= dead;
ship.Cargo[(int)TradeItemType.Furs] += dead;
ship.Tribbles -= Math.Min(dead * (Functions.GetRandom(5) + 98), ship.Tribbles - 1);
FormAlert.Alert(AlertType.TribblesMostDied, ParentWindow);
}
else
{
if (ship.Cargo[food] > 0 && ship.Tribbles < Consts.MaxTribbles)
{
int eaten = ship.Cargo[food] - Functions.GetRandom(ship.Cargo[food]);
Commander.PriceCargo[food] -= Commander.PriceCargo[food] * eaten / ship.Cargo[food];
ship.Cargo[food] -= eaten;
ship.Tribbles += eaten * 100;
FormAlert.Alert(AlertType.TribblesAteFood, ParentWindow);
}
if (ship.Tribbles < Consts.MaxTribbles)
ship.Tribbles += 1 + Functions.GetRandom(ship.Cargo[food] > 0 ? ship.Tribbles : ship.Tribbles / 2);
if (ship.Tribbles > Consts.MaxTribbles)
ship.Tribbles = Consts.MaxTribbles;
if ((previousTribbles < 100 && ship.Tribbles >= 100) ||
(previousTribbles < 1000 && ship.Tribbles >= 1000) ||
(previousTribbles < 10000 && ship.Tribbles >= 10000) ||
(previousTribbles < 50000 && ship.Tribbles >= 50000) ||
(previousTribbles < Consts.MaxTribbles && ship.Tribbles == Consts.MaxTribbles))
{
string qty = ship.Tribbles == Consts.MaxTribbles ? Strings.TribbleDangerousNumber :
Functions.FormatNumber(ship.Tribbles);
FormAlert.Alert(AlertType.TribblesInspector, ParentWindow, qty);
}
}
TribbleMessage = false;
}
}
private void ArrivalPerformRepairs()
{
Ship ship = Commander.Ship;
if (ship.Hull < ship.HullStrength)
ship.Hull += Math.Min(ship.HullStrength - ship.Hull, Functions.GetRandom(ship.Engineer));
for (int i = 0; i < ship.Shields.Length; ++i)
if (ship.Shields[i] != null)
ship.Shields[i].Charge = ship.Shields[i].Power;
bool fuelOk = true;
int toAdd = ship.FuelTanks - ship.Fuel;
if (Options.AutoFuel && toAdd > 0)
{
if (Commander.Cash >= toAdd * ship.FuelCost)
{
ship.Fuel += toAdd;
Commander.Cash -= toAdd * ship.FuelCost;
}
else
fuelOk = false;
}
bool repairOk = true;
toAdd = ship.HullStrength - ship.Hull;
if (Options.AutoRepair && toAdd > 0)
{
if (Commander.Cash >= toAdd * ship.RepairCost)
{
ship.Hull += toAdd;
Commander.Cash -= toAdd * ship.RepairCost;
}
else
repairOk = false;
}
if (!fuelOk && !repairOk)
FormAlert.Alert(AlertType.ArrivalIfFuelRepairs, ParentWindow);
else if (!fuelOk)
FormAlert.Alert(AlertType.ArrivalIfFuel, ParentWindow);
else if (!repairOk)
FormAlert.Alert(AlertType.ArrivalIfRepairs, ParentWindow);
}
private void ArrivalUpdatePressuresAndQuantities()
{
for (int i = 0; i < Universe.Length; i++)
{
if (Functions.GetRandom(100) < 15)
Universe[i].SystemPressure = Universe[i].SystemPressure == SystemPressure.None ?
(SystemPressure)Functions.GetRandom((int)SystemPressure.War,
(int)SystemPressure.Employment + 1) : SystemPressure.None;
if (Universe[i].CountDown > 0)
{
Universe[i].CountDown--;
if (Universe[i].CountDown > CountDownStart)
Universe[i].CountDown = CountDownStart;
else if (Universe[i].CountDown <= 0)
Universe[i].InitializeTradeItems();
else
{
for (int j = 0; j < Consts.TradeItems.Length; j++)
{
if (WarpSystem.ItemTraded(Consts.TradeItems[j]))
Universe[i].TradeItems[j] = Math.Max(0, Universe[i].TradeItems[j] + Functions.GetRandom(-4, 5));
}
}
}
}
}
private void CalculatePrices(StarSystem system)
{
for (int i = 0; i < Consts.TradeItems.Length; i++)
{
int price = Consts.TradeItems[i].StandardPrice(system);
if (price > 0)
{
// In case of a special status, adapt price accordingly
if (Consts.TradeItems[i].PressurePriceHike == system.SystemPressure)
price = price * 3 / 2;
// Randomize price a bit
int variance = Math.Min(Consts.TradeItems[i].PriceVariance, price - 1);
price = price + Functions.GetRandom(-variance, variance + 1);
// Criminals have to pay off an intermediary
if (Commander.PoliceRecordScore < Consts.PoliceRecordScoreDubious)
price = price * 90 / 100;
}
_priceCargoSell[i] = price;
}
RecalculateBuyPrices(system);
}
private void CargoBuy(int tradeItem, bool max, IWin32Window owner, CargoBuyOp op)
{
int freeBays = Commander.Ship.FreeCargoBays;
int[] items = null;
int unitPrice = 0;
int cashToSpend = Commander.Cash;
switch (op)
{
case CargoBuyOp.BuySystem:
freeBays = Math.Max(0, Commander.Ship.FreeCargoBays - Options.LeaveEmpty);
items = Commander.CurrentSystem.TradeItems;
unitPrice = PriceCargoBuy[tradeItem];
cashToSpend = Commander.CashToSpend;
break;
case CargoBuyOp.BuyTrader:
items = Opponent.Cargo;
TradeItem item = Consts.TradeItems[tradeItem];
int chance = item.Illegal ? 45 : 10;
double adj = Functions.GetRandom(100) < chance ? 1.1 : (item.Illegal ? 0.8 : 0.9);
unitPrice = Math.Min(item.MaxTradePrice, Math.Max(item.MinTradePrice,
(int)Math.Round(PriceCargoBuy[tradeItem] * adj / item.RoundOff) * item.RoundOff));
break;
case CargoBuyOp.Plunder:
items = Opponent.Cargo;
break;
}
if (op == CargoBuyOp.BuySystem && Commander.Debt > Consts.DebtTooLarge)
FormAlert.Alert(AlertType.DebtTooLargeTrade, owner);
else if (op == CargoBuyOp.BuySystem && (items[tradeItem] <= 0 || unitPrice <= 0))
FormAlert.Alert(AlertType.CargoNoneAvailable, owner);
else if (freeBays == 0)
FormAlert.Alert(AlertType.CargoNoEmptyBays, owner);
else if (op != CargoBuyOp.Plunder && cashToSpend < unitPrice)
FormAlert.Alert(AlertType.CargoIf, owner);
else
{
int qty = 0;
int maxAmount = Math.Min(freeBays, items[tradeItem]);
if (op == CargoBuyOp.BuySystem)
maxAmount = Math.Min(maxAmount, Commander.CashToSpend / unitPrice);
if (max)
qty = maxAmount;
else
{
FormCargoBuy form = new FormCargoBuy(tradeItem, maxAmount, op);
if (form.ShowDialog(owner) == DialogResult.OK)
qty = form.Amount;
}
if (qty > 0)
{
int totalPrice = qty * unitPrice;
Commander.Ship.Cargo[tradeItem] += qty;
items[tradeItem] -= qty;
Commander.Cash -= totalPrice;
Commander.PriceCargo[tradeItem] += totalPrice;
}
}
}
public void CargoBuySystem(int tradeItem, bool max, IWin32Window owner)
{
CargoBuy(tradeItem, max, owner, CargoBuyOp.BuySystem);
}
public void CargoBuyTrader(int tradeItem, IWin32Window owner)
{
CargoBuy(tradeItem, false, owner, CargoBuyOp.BuyTrader);
}
public void CargoPlunder(int tradeItem, bool max, IWin32Window owner)
{
CargoBuy(tradeItem, max, owner, CargoBuyOp.Plunder);
}
public void CargoDump(int tradeItem, IWin32Window owner)
{
CargoSell(tradeItem, false, owner, CargoSellOp.Dump);
}
public void CargoJettison(int tradeItem, bool all, IWin32Window owner)
{
CargoSell(tradeItem, all, owner, CargoSellOp.Jettison);
}
public void CargoSellSystem(int tradeItem, bool all, IWin32Window owner)
{
CargoSell(tradeItem, all, owner, CargoSellOp.SellSystem);
}
private void CargoSell(int tradeItem, bool all, IWin32Window owner, CargoSellOp op)
{
int qtyInHand = Commander.Ship.Cargo[tradeItem];
int unitPrice;
switch (op)
{
case CargoSellOp.SellSystem:
unitPrice = PriceCargoSell[tradeItem];
break;
case CargoSellOp.SellTrader:
TradeItem item = Consts.TradeItems[tradeItem];
int chance = item.Illegal ? 45 : 10;
double adj = Functions.GetRandom(100) < chance ? (item.Illegal ? 0.8 : 0.9) : 1.1;
unitPrice = Math.Min(item.MaxTradePrice, Math.Max(item.MinTradePrice,
(int)Math.Round(PriceCargoSell[tradeItem] * adj / item.RoundOff) * item.RoundOff));
break;
default:
unitPrice = 0;
break;
}
if (qtyInHand == 0)
FormAlert.Alert(AlertType.CargoNoneToSell, owner, Strings.CargoSellOps[(int)op]);
else if (op == CargoSellOp.SellSystem && unitPrice <= 0)
FormAlert.Alert(AlertType.CargoNotInterested, owner);
else
{
if (op != CargoSellOp.Jettison || LitterWarning ||
Commander.PoliceRecordScore <= Consts.PoliceRecordScoreDubious ||
FormAlert.Alert(AlertType.EncounterDumpWarning, owner) == DialogResult.Yes)
{
int unitCost = 0;
int maxAmount = (op == CargoSellOp.SellTrader) ? Math.Min(qtyInHand, Opponent.FreeCargoBays) : qtyInHand;
if (op == CargoSellOp.Dump)
{
unitCost = 5 * ((int)Difficulty + 1);
maxAmount = Math.Min(maxAmount, Commander.CashToSpend / unitCost);
}
int price = unitPrice > 0 ? unitPrice : -unitCost;
int qty = 0;
if (all)
qty = maxAmount;
else
{
FormCargoSell form = new FormCargoSell(tradeItem, maxAmount, op, price);
if (form.ShowDialog(owner) == DialogResult.OK)
qty = form.Amount;
}
if (qty > 0)
{
int totalPrice = qty * price;
Commander.Ship.Cargo[tradeItem] -= qty;
Commander.PriceCargo[tradeItem] = (Commander.PriceCargo[tradeItem] * (qtyInHand - qty)) / qtyInHand;
Commander.Cash += totalPrice;
if (op == CargoSellOp.Jettison)
{
if (Functions.GetRandom(10) < (int)Difficulty + 1)
{
if (Commander.PoliceRecordScore > Consts.PoliceRecordScoreDubious)
Commander.PoliceRecordScore = Consts.PoliceRecordScoreDubious;
else
Commander.PoliceRecordScore--;
NewsAddEvent(NewsEvent.CaughtLittering);
}
}
}
}
}
}
public void CargoSellTrader(int tradeItem, IWin32Window owner)
{
CargoSell(tradeItem, false, owner, CargoSellOp.SellTrader);
}
public void CreateFlea()
{
Commander.Ship = new Ship(ShipType.Flea);
Commander.Ship.Crew[0] = Commander;
Commander.Insurance = false;
Commander.NoClaim = 0;
}
private void CreateShips()
{
Dragonfly.Crew[0] = Mercenaries[(int)CrewMemberId.Dragonfly];
Dragonfly.AddEquipment(Consts.Weapons[(int)WeaponType.MilitaryLaser]);
Dragonfly.AddEquipment(Consts.Weapons[(int)WeaponType.PulseLaser]);
Dragonfly.AddEquipment(Consts.Shields[(int)ShieldType.Lightning]);
Dragonfly.AddEquipment(Consts.Shields[(int)ShieldType.Lightning]);
Dragonfly.AddEquipment(Consts.Shields[(int)ShieldType.Lightning]);
Dragonfly.AddEquipment(Consts.Gadgets[(int)GadgetType.AutoRepairSystem]);
Dragonfly.AddEquipment(Consts.Gadgets[(int)GadgetType.TargetingSystem]);
Scarab.Crew[0] = Mercenaries[(int)CrewMemberId.Scarab];
Scarab.AddEquipment(Consts.Weapons[(int)WeaponType.MilitaryLaser]);
Scarab.AddEquipment(Consts.Weapons[(int)WeaponType.MilitaryLaser]);
Scorpion.Crew[0] = Mercenaries[(int)CrewMemberId.Scorpion];
Scorpion.AddEquipment(Consts.Weapons[(int)WeaponType.MilitaryLaser]);
Scorpion.AddEquipment(Consts.Weapons[(int)WeaponType.MilitaryLaser]);
Scorpion.AddEquipment(Consts.Shields[(int)ShieldType.Reflective]);
Scorpion.AddEquipment(Consts.Shields[(int)ShieldType.Reflective]);
Scorpion.AddEquipment(Consts.Gadgets[(int)GadgetType.AutoRepairSystem]);
Scorpion.AddEquipment(Consts.Gadgets[(int)GadgetType.TargetingSystem]);
SpaceMonster.Crew[0] = Mercenaries[(int)CrewMemberId.SpaceMonster];
SpaceMonster.AddEquipment(Consts.Weapons[(int)WeaponType.MilitaryLaser]);
SpaceMonster.AddEquipment(Consts.Weapons[(int)WeaponType.MilitaryLaser]);
SpaceMonster.AddEquipment(Consts.Weapons[(int)WeaponType.MilitaryLaser]);
}
private bool DetermineEncounter()
{
// If there is a specific encounter that needs to happen, it will, otherwise we'll generate a random encounter.
return DetermineNonRandomEncounter() || DetermineRandomEncounter();
}
private bool DetermineNonRandomEncounter()
{
bool showEncounter = false;
// Encounter with space monster
if (Clicks == 1 && WarpSystem.Id == StarSystemId.Acamar &&
QuestStatusSpaceMonster == SpecialEvent.StatusSpaceMonsterAtAcamar)
{
Opponent = SpaceMonster;
EncounterType = Commander.Ship.Cloaked ? EncounterType.SpaceMonsterIgnore : EncounterType.SpaceMonsterAttack;
showEncounter = true;
}
// Encounter with the stolen Scarab
else if (ArrivedViaWormhole && Clicks == 20 && WarpSystem.SpecialEventType != SpecialEventType.Na &&
WarpSystem.SpecialEvent.Type == SpecialEventType.ScarabDestroyed &&
QuestStatusScarab == SpecialEvent.StatusScarabHunting)
{
Opponent = Scarab;
EncounterType = Commander.Ship.Cloaked ? EncounterType.ScarabIgnore : EncounterType.ScarabAttack;
showEncounter = true;
}
// Encounter with stolen Dragonfly
else if (Clicks == 1 && WarpSystem.Id == StarSystemId.Zalkon &&
QuestStatusDragonfly == SpecialEvent.StatusDragonflyFlyZalkon)
{
Opponent = Dragonfly;
EncounterType = Commander.Ship.Cloaked ? EncounterType.DragonflyIgnore : EncounterType.DragonflyAttack;
showEncounter = true;
}
// Encounter with kidnappers in the Scorpion
else if (Clicks == 1 && WarpSystem.Id == StarSystemId.Qonos &&
QuestStatusPrincess == SpecialEvent.StatusPrincessFlyQonos)
{
Opponent = Scorpion;
EncounterType = Commander.Ship.Cloaked ? EncounterType.ScorpionIgnore : EncounterType.ScorpionAttack;
showEncounter = true;
}
// ah, just when you thought you were gonna get away with it...
else if (Clicks == 1 && JustLootedMarie)
{
GenerateOpponent(OpponentType.Police);
EncounterType = EncounterType.MarieCelestePolice;
JustLootedMarie = false;
showEncounter = true;
}
return showEncounter;
}
private bool DeterminePirateEncounter(bool mantis)
{
bool showEncounter = false;
if (mantis)
{
GenerateOpponent(OpponentType.Mantis);
EncounterType = EncounterType.PirateAttack;
}
else
{
GenerateOpponent(OpponentType.Pirate);
// If you have a cloak, they don't see you
if (Commander.Ship.Cloaked)
EncounterType = EncounterType.PirateIgnore;
// Pirates will mostly attack, but they are cowardly: if your rep is too high, they tend to flee
// if Pirates are in a better ship, they won't flee, even if you have a very scary
// reputation.
else if (Opponent.Type > Commander.Ship.Type || Opponent.Type >= ShipType.Grasshopper ||
Functions.GetRandom(Consts.ReputationScoreElite) >
(Commander.ReputationScore * 4) / (1 + (int)Opponent.Type))
EncounterType = EncounterType.PirateAttack;
else
EncounterType = EncounterType.PirateFlee;
}
// If they ignore you or flee and you can't see them, the encounter doesn't take place
// If you automatically don't want to confront someone who ignores you, the
// encounter may not take place
if (EncounterType == EncounterType.PirateAttack || !(Opponent.Cloaked || Options.AlwaysIgnorePirates))
showEncounter = true;
return showEncounter;
}
private bool DeterminePoliceEncounter()
{
bool showEncounter = false;
GenerateOpponent(OpponentType.Police);
// If you are cloaked, they don't see you
EncounterType = EncounterType.PoliceIgnore;
if (!Commander.Ship.Cloaked)
{
if (Commander.PoliceRecordScore < Consts.PoliceRecordScoreDubious)
{
// If you're a criminal, the police will tend to attack
// JAF - fixed this; there was code that didn't do anything.
// if you're suddenly stuck in a lousy ship, Police won't flee even if you
// have a fearsome reputation.
if (Opponent.WeaponStrength() > 0 && (Commander.ReputationScore < Consts.ReputationScoreAverage ||
Functions.GetRandom(Consts.ReputationScoreElite) >
(Commander.ReputationScore / (1 + (int)Opponent.Type))) || Opponent.Type > Commander.Ship.Type)
{
if (Commander.PoliceRecordScore >= Consts.PoliceRecordScoreCriminal)
EncounterType = EncounterType.PoliceSurrender;
else
EncounterType = EncounterType.PoliceAttack;
}
else if (Opponent.Cloaked)
EncounterType = EncounterType.PoliceIgnore;
else
EncounterType = EncounterType.PoliceFlee;
}
else if (!Inspected && (Commander.PoliceRecordScore < Consts.PoliceRecordScoreClean ||
(Commander.PoliceRecordScore < Consts.PoliceRecordScoreLawful &&
Functions.GetRandom(12 - (int)Difficulty) < 1) ||
(Commander.PoliceRecordScore >= Consts.PoliceRecordScoreLawful && Functions.GetRandom(40) == 0)))
{
// If you're reputation is dubious, the police will inspect you
// If your record is clean, the police will inspect you with a chance of 10% on Normal
// If your record indicates you are a lawful trader, the chance on inspection drops to 2.5%
EncounterType = EncounterType.PoliceInspect;
Inspected = true;
}
}
// If they ignore you or flee and you can't see them, the encounter doesn't take place
// If you automatically don't want to confront someone who ignores you, the
// encounter may not take place. Otherwise it will - JAF
if (EncounterType == EncounterType.PoliceAttack || EncounterType == EncounterType.PoliceInspect ||
!(Opponent.Cloaked || Options.AlwaysIgnorePolice))
showEncounter = true;
return showEncounter;
}
private bool DetermineRandomEncounter()
{
bool showEncounter = false;
bool mantis = false;
bool pirate = false;
bool police = false;
bool trader = false;
if (WarpSystem.Id == StarSystemId.Gemulon && QuestStatusGemulon == SpecialEvent.StatusGemulonTooLate)
{
if (Functions.GetRandom(10) > 4)
mantis = true;
}
else
{
// Check if it is time for an encounter
int encounter = Functions.GetRandom(44 - (2 * (int)Difficulty));
int policeModifier = Math.Max(1, 3 - (int)PoliceRecord.GetPoliceRecordFromScore(Commander.PoliceRecordScore).Type);
// encounters are half as likely if you're in a flea.
if (Commander.Ship.Type == ShipType.Flea)
encounter *= 2;
if (encounter < (int)WarpSystem.PoliticalSystem.ActivityPirates)
// When you are already raided, other pirates have little to gain
pirate = !Raided;
else if (encounter < (int)WarpSystem.PoliticalSystem.ActivityPirates +
(int)WarpSystem.PoliticalSystem.ActivityPolice * policeModifier)
// policeModifier adapts itself to your criminal record: you'll
// encounter more police if you are a hardened criminal.
police = true;
else if (encounter < (int)WarpSystem.PoliticalSystem.ActivityPirates +
(int)WarpSystem.PoliticalSystem.ActivityPolice * policeModifier +
(int)WarpSystem.PoliticalSystem.ActivityTraders)
trader = true;
else if (Commander.Ship.WildOnBoard && WarpSystem.Id == StarSystemId.Kravat)
// if you're coming in to Kravat & you have Wild on board, there'll be swarms o' cops.
police = Functions.GetRandom(100) < 100 / Math.Max(2, Math.Min(4, 5 - (int)Difficulty));
else if (Commander.Ship.ArtifactOnBoard && Functions.GetRandom(20) <= 3)
mantis = true;
}
if (police)
showEncounter = DeterminePoliceEncounter();
else if (pirate || mantis)
showEncounter = DeterminePirateEncounter(mantis);
else if (trader)
showEncounter = DetermineTraderEncounter();
else if (Commander.Days > 10 && Functions.GetRandom(1000) < ChanceOfVeryRareEncounter &&
VeryRareEncounters.Count > 0)
showEncounter = DetermineVeryRareEncounter();
return showEncounter;
}
private bool DetermineTraderEncounter()
{
bool showEncounter = false;
GenerateOpponent(OpponentType.Trader);
// If you are cloaked, they don't see you
EncounterType = EncounterType.TraderIgnore;
if (!Commander.Ship.Cloaked)
{
// If you're a criminal, traders tend to flee if you've got at least some reputation
if (!Commander.Ship.Cloaked && Commander.PoliceRecordScore <= Consts.PoliceRecordScoreCriminal &&
Functions.GetRandom(Consts.ReputationScoreElite) <= (Commander.ReputationScore * 10) / (1 + (int)Opponent.Type))
EncounterType = EncounterType.TraderFlee;
// Will there be trade in orbit?
else if (Functions.GetRandom(1000) < ChanceOfTradeInOrbit)
{
if (Commander.Ship.FreeCargoBays > 0 && Opponent.HasTradeableItems())
EncounterType = EncounterType.TraderSell;
// we fudge on whether the trader has capacity to carry the stuff he's buying.
else if (Commander.Ship.HasTradeableItems())
EncounterType = EncounterType.TraderBuy;
}
}
// If they ignore you or flee and you can't see them, the encounter doesn't take place
// If you automatically don't want to confront someone who ignores you, the
// encounter may not take place; otherwise it will.
if (!Opponent.Cloaked && !(Options.AlwaysIgnoreTraders &&
(EncounterType == EncounterType.TraderIgnore || EncounterType == EncounterType.TraderFlee)) &&
!((EncounterType == EncounterType.TraderBuy || EncounterType == EncounterType.TraderSell) &&
Options.AlwaysIgnoreTradeInOrbit))
showEncounter = true;
return showEncounter;