-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathCArmorClass.cpp
2687 lines (1988 loc) · 71.6 KB
/
CArmorClass.cpp
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
// CArmorClass.cpp
//
// CArmorClass class
#include "PreComp.h"
#define BLINDING_DAMAGE_ADJ_ATTRIB CONSTLIT("blindingDamageAdj")
#define BLINDING_IMMUNE_ATTRIB CONSTLIT("blindingImmune")
#define CHARGE_DECAY_ATTRIB CONSTLIT("chargeDecay")
#define CHARGE_REGEN_ATTRIB CONSTLIT("chargeRegen")
#define COMPLETE_BONUS_ATTRIB CONSTLIT("completeBonus")
#define DAMAGE_ADJ_LEVEL_ATTRIB CONSTLIT("damageAdjLevel")
#define DECAY_ATTRIB CONSTLIT("decay")
#define DECAY_RATE_ATTRIB CONSTLIT("decayRate")
#define DEVICE_CRITERIA_ATTRIB CONSTLIT("deviceCriteria")
#define DEVICE_DAMAGE_ADJ_ATTRIB CONSTLIT("deviceDamageAdj")
#define DEVICE_DAMAGE_IMMUNE_ATTRIB CONSTLIT("deviceDamageImmune")
#define DEVICE_HP_BONUS_ATTRIB CONSTLIT("deviceHPBonus")
#define DISTRIBUTE_ATTRIB CONSTLIT("distribute")
#define DISINTEGRATION_IMMUNE_ATTRIB CONSTLIT("disintegrationImmune")
#define ENHANCEMENT_TYPE_ATTRIB CONSTLIT("enhancementType")
#define EMP_DAMAGE_ADJ_ATTRIB CONSTLIT("EMPDamageAdj")
#define EMP_IMMUNE_ATTRIB CONSTLIT("EMPImmune")
#define HIT_POINTS_ATTRIB CONSTLIT("hitPoints")
#define HP_BONUS_PER_CHARGE_ATTRIB CONSTLIT("hpBonusPerCharge")
#define IDLE_POWER_USE_ATTRIB CONSTLIT("idlePowerUse")
#define INSTALL_COST_ATTRIB CONSTLIT("installCost")
#define INSTALL_COST_ADJ_ATTRIB CONSTLIT("installCostAdj")
#define MAX_HP_BONUS_ATTRIB CONSTLIT("maxHPBonus")
#define MAX_SPEED_ATTRIB CONSTLIT("maxSpeed")
#define MAX_SPEED_INC_ATTRIB CONSTLIT("maxSpeedInc")
#define PHOTO_RECHARGE_ATTRIB CONSTLIT("photoRecharge")
#define PHOTO_REPAIR_ATTRIB CONSTLIT("photoRepair")
#define POWER_USE_ATTRIB CONSTLIT("powerUse")
#define RADIATION_IMMUNE_ATTRIB CONSTLIT("radiationImmune")
#define REFLECT_ATTRIB CONSTLIT("reflect")
#define REGEN_ATTRIB CONSTLIT("regen")
#define REGEN_TYPE_ATTRIB CONSTLIT("regenType")
#define REPAIR_COST_ATTRIB CONSTLIT("repairCost")
#define REPAIR_COST_ADJ_ATTRIB CONSTLIT("repairCostAdj")
#define REPAIR_RATE_ATTRIB CONSTLIT("repairRate")
#define REPAIR_TECH_ATTRIB CONSTLIT("repairTech")
#define SHATTER_IMMUNE_ATTRIB CONSTLIT("shatterImmune")
#define SHIELD_INTERFERENCE_ATTRIB CONSTLIT("shieldInterference")
#define STEALTH_ATTRIB CONSTLIT("stealth")
#define UNID_ATTRIB CONSTLIT("unid")
#define HEALER_REGEN_ATTRIB CONSTLIT("useHealerToRegen")
#define GET_MAX_HP_EVENT CONSTLIT("GetMaxHP")
#define ON_ARMOR_CONSUME_POWER_EVENT CONSTLIT("OnArmorConsumePower")
#define ON_ARMOR_DAMAGE_EVENT CONSTLIT("OnArmorDamage")
#define FIELD_ADJUSTED_HP CONSTLIT("adjustedHP")
#define FIELD_BALANCE CONSTLIT("balance")
#define FIELD_DAMAGE_ADJ CONSTLIT("damageAdj")
#define FIELD_EFFECTIVE_HP CONSTLIT("effectiveHP")
#define FIELD_HP CONSTLIT("hp")
#define FIELD_HP_BONUS CONSTLIT("hpBonus")
#define FIELD_INSTALL_COST CONSTLIT("installCost")
#define FIELD_REGEN CONSTLIT("regen")
#define FIELD_REPAIR_COST CONSTLIT("repairCost")
#define FIELD_SHIELD_INTERFERENCE CONSTLIT("shieldInterference")
#define PROPERTY_ARMOR_CLASS CONSTLIT("armorClass")
#define PROPERTY_BLINDING_IMMUNE CONSTLIT("blindingImmune")
#define PROPERTY_COMPLETE_HP CONSTLIT("completeHP")
#define PROPERTY_COMPLETE_SET CONSTLIT("completeSet")
#define PROPERTY_DAMAGE_ADJ CONSTLIT("damageAdj")
#define PROPERTY_DEVICE_DAMAGE_IMMUNE CONSTLIT("deviceDamageImmune")
#define PROPERTY_DEVICE_DISRUPT_IMMUNE CONSTLIT("deviceDisruptImmune")
#define PROPERTY_DISINTEGRATION_IMMUNE CONSTLIT("disintegrationImmune")
#define PROPERTY_EMP_IMMUNE CONSTLIT("EMPImmune")
#define PROPERTY_HP CONSTLIT("hp")
#define PROPERTY_HP_BONUS CONSTLIT("hpBonus")
#define PROPERTY_MAX_HP CONSTLIT("maxHP")
#define PROPERTY_PRIME_SEGMENT CONSTLIT("primeSegment")
#define PROPERTY_RADIATION_IMMUNE CONSTLIT("radiationImmune")
#define PROPERTY_REGEN CONSTLIT("regen")
#define PROPERTY_REPAIR_COST CONSTLIT("repairCost")
#define PROPERTY_REPAIR_LEVEL CONSTLIT("repairLevel")
#define PROPERTY_SHATTER_IMMUNE CONSTLIT("shatterImmune")
#define PROPERTY_STD_HP CONSTLIT("stdHP")
constexpr int MAX_REFLECTION_CHANCE = 95;
constexpr int ARMOR_HP_PER_SHIELD_HP = 4;
constexpr int BLIND_IMMUNE_LEVEL = 6;
constexpr int RADIATION_IMMUNE_LEVEL = 7;
constexpr int EMP_IMMUNE_LEVEL = 9;
constexpr int DEVICE_DAMAGE_IMMUNE_LEVEL = 11;
constexpr int DISINTEGRATION_IMMUNE_LEVEL = 15;
constexpr int SHATTER_IMMUNE_LEVEL = 19;
const Metric PHOTO_REPAIR_ADJ = 0.6;
const Metric RADIATION_IMMUNE_BALANCE_BONUS = 25.0;
const Metric RADIATION_VULNERABLE_BALANCE_BONUS = -25.0;
const Metric BLIND_IMMUNE_BALANCE_BONUS = 10.0;
const Metric BLIND_VULNERABLE_BALANCE_BONUS = -10.0;
const Metric EMP_IMMUNE_BALANCE_BONUS = 25.0;
const Metric EMP_VULNERABLE_BALANCE_BONUS = -25.0;
const Metric DEVICE_DAMAGE_IMMUNE_BALANCE_BONUS = 25.0;
const Metric DEVICE_DAMAGE_VULNERABLE_BALANCE_BONUS = -25.0;
const Metric SHATTER_IMMUNE_BALANCE_BONUS = 20.0;
const Metric SHATTER_VULNERABLE_BALANCE_BONUS = -20.0;
const Metric DISINTEGRATION_IMMUNE_BALANCE_BONUS = 10.0;
const Metric DISINTEGRATION_VULNERABLE_BALANCE_BONUS = -20.0;
const Metric HIGHER_REPAIR_LEVEL_BALANCE_BONUS = -5.0;
const Metric LOWER_REPAIR_LEVEL_BALANCE_BONUS = 2.5;
const Metric ARMOR_COMPLETE_BALANCE_ADJ = -0.20;
const Metric STEALTH_BALANCE_BONUS = 5.0;
const Metric REFLECTION_BALANCE_BONUS = 50.0;
const Metric POWER_USE_BALANCE_ADJ = -400.0;
const Metric PHOTO_RECHARGE_BALANCE_ADJ = 25.0;
const Metric MAX_SPEED_BALANCE_BONUS = 10;
const Metric SHIELD_INTERFERENCE_BALANCE_BONUS = -150.0;
const Metric REGEN_BALANCE_ADJ = 10.0; // For each percent of regen/stdweapon ratio
const Metric DECAY_BALANCE_ADJ = -3.0;
const Metric DIST_BALANCE_ADJ = 2.0;
const Metric MAX_REGEN_BALANCE_BONUS = 500.0;
const Metric MASS_BALANCE_K0 = 1.284;
const Metric MASS_BALANCE_K1 = -0.47;
const Metric MASS_BALANCE_K2 = 0.014;
const Metric MASS_BALANCE_ADJ = 60.0; // Linear relationship between curve and mass balance
const Metric MASS_BALANCE_LIMIT = 16.0; // Above this mass (in tons) we don't get any additional bonus
const Metric BALANCE_COST_RATIO = -0.5; // Each percent of cost above standard is a 0.5%
const Metric BALANCE_MAX_DAMAGE_ADJ = 400.0; // Max change in balance due to a single damage type
static CArmorClass::SStdStats STD_STATS[MAX_ITEM_LEVEL] =
{
// Repair Install
// HP Cost cost cost Mass
{ 35, 50, 1, 10, 2500, },
{ 45, 100, 1, 20, 2600, },
{ 60, 200, 1, 40, 2800, },
{ 80, 400, 2, 80, 2900, },
{ 100, 800, 3, 160, 3000, },
{ 135, 1600, 4, 320, 3000, },
{ 175, 3200, 6, 640, 3000, },
{ 225, 6500, 9, 1300, 3000, },
{ 300, 13000, 15, 2600, 3000, },
{ 380, 25000, 22, 5000, 3000, },
{ 500, 50000, 35, 10000, 3000, },
{ 650, 100000, 52, 20000, 3000, },
{ 850, 200000, 80, 40000, 3000, },
{ 1100, 410000, 125, 82000, 3000, },
{ 1400, 820000, 190, 164000, 3000, },
{ 1850, 1600000, 300, 320000, 3000, },
{ 2400, 3250000, 450, 650000, 3000, },
{ 3100, 6500000, 700, 1300000, 3000, },
{ 4000, 13000000, 1050, 2600000, 3000, },
{ 5250, 26000000, 1650, 5200000, 3000, },
{ 6850, 52000000, 2540, 10400000, 3000, },
{ 9000, 100000000, 3900, 20000000, 3000, },
{ 12000, 200000000, 6000, 40000000, 3000, },
{ 15000, 400000000, 9300, 80000000, 3000, },
{ 20000, 800000000, 14300, 160000000, 3000, },
};
static char *CACHED_EVENTS[CArmorClass::evtCount] =
{
"GetMaxHP",
"OnArmorConsumePower",
"OnArmorDamage",
};
static TStaticStringTable<TStaticStringEntry<ERegenTypes>, 5> REGEN_TYPE_TABLE = {
"charges", regenFromCharges,
"healer", regenFromHealer,
"photorepair", regenSolar,
"shields", regenFromShields,
"standard", regenStandard,
};
CArmorClass::CArmorClass (void) :
m_pItemType(NULL),
m_iScaledLevels(0),
m_pScalable(NULL)
// CArmorClass constructor
{
}
CArmorClass::~CArmorClass (void)
// CArmorClass destructor
{
if (m_pScalable)
delete[] m_pScalable;
}
EDamageResults CArmorClass::AbsorbDamage (CItemCtx &ItemCtx, SDamageCtx &Ctx)
// AbsorbDamage
//
// Handles getting hit by damage.
//
// Returns damageNoDamage if all the damage was absorbed and no further processing is necessary
// Returns damageDestroyed if the source was destroyed
// Returns damageArmorHit if source was damage and further processing (destroy check) is needed
// Returns damageDisintegrated if source should be disintegrated
// Returns damageShattered if source should be shattered
//
// Sets Ctx.iDamage to the amount of hit points left after damage absorption.
{
DEBUG_TRY
CSpaceObject *pSource = ItemCtx.GetSource();
CInstalledArmor *pArmor = ItemCtx.GetArmor();
if (pSource == NULL || pArmor == NULL)
return damageNoDamage;
// Compute all the effects (this initializes elements in Ctx).
CalcDamageEffects(ItemCtx, Ctx);
// First give custom weapons a chance
bool bCustomDamage = (Ctx.pDesc && Ctx.pDesc->FireOnDamageArmor(Ctx));
if (pSource->IsDestroyed())
return damageDestroyed;
// Damage adjustment. This initializes Ctx.iArmorDamage.
CalcAdjustedDamage(ItemCtx, Ctx);
// If the armor has custom code to deal with damage, handle it here.
FireOnArmorDamage(ItemCtx, Ctx);
if (pSource->IsDestroyed())
return damageDestroyed;
// If this armor section reflects this kind of damage then
// send the damage on
if (Ctx.IsShotReflected())
{
if (Ctx.pCause)
Ctx.pCause->CreateReflection(Ctx.vHitPos, (Ctx.iDirection + 120 + mathRandom(0, 120)) % 360);
return damageNoDamage;
}
// If this is a disintegration attack, then disintegrate the ship
if (Ctx.IsDisintegrated())
{
Ctx.Damage.SetCause(killedByDisintegration);
return damageDisintegrated;
}
// If this is a shatter attack, see if the ship is destroyed
if (Ctx.IsShattered())
{
Ctx.Damage.SetCause(killedByShatter);
return damageShattered;
}
// If this is a paralysis attack and we've gotten past the shields
// then freeze the ship.
if (Ctx.IsParalyzed())
pSource->SetConditionDueToDamage(Ctx, CConditionSet::cndParalyzed);
// If this is blinding damage then our sensors are disabled
if (Ctx.IsBlinded())
pSource->SetConditionDueToDamage(Ctx, CConditionSet::cndBlind);
// If this attack is radioactive, then contaminate the ship
if (Ctx.IsRadioactive())
pSource->SetConditionDueToDamage(Ctx, CConditionSet::cndRadioactive);
// If this is device damage, then see if any device is damaged
if (Ctx.IsDeviceDamaged())
pSource->OnHitByDeviceDamage();
if (Ctx.IsDeviceDisrupted())
pSource->OnHitByDeviceDisruptDamage(Ctx.GetDeviceDisruptTime());
// Create a hit effect. (Many weapons show an effect even if no damage was
// done.)
if (!Ctx.bNoHitEffect && Ctx.pDesc)
Ctx.pDesc->CreateHitEffect(pSource->GetSystem(), Ctx);
// Give source events a chance to change the damage before we
// subtract from armor.
if (pSource->HasOnDamageEvent())
{
Ctx.iArmorDamage = pSource->FireOnDamage(Ctx, Ctx.iArmorDamage);
if (pSource->IsDestroyed())
return damageDestroyed;
}
// Compute how much damage the armor absorbs based on how much damage it
// took.
if (pArmor->GetHitPoints() == 0)
Ctx.iArmorAbsorb = 0;
else if (Ctx.iArmorDamage <= pArmor->GetHitPoints())
Ctx.iArmorAbsorb = Ctx.iDamage;
else
Ctx.iArmorAbsorb = pArmor->GetHitPoints() * Ctx.iDamage / Ctx.iArmorDamage;
// Absorb damage
Ctx.iDamage = Max(0, Ctx.iDamage - Ctx.iArmorAbsorb);
pArmor->IncHitPoints(-Ctx.iArmorDamage);
// If we took no damage, then say so.
if (Ctx.iArmorDamage == 0 && !bCustomDamage)
return damageNoDamage;
else
return damageArmorHit;
DEBUG_CATCH
}
void CArmorClass::AccumulateAttributes (CItemCtx &ItemCtx, TArray<SDisplayAttribute> *retList)
// AccumulateAttributes
//
// Returns list of display attributes. NOTE: We only include our intrinsic
// attributes--enhancements are added later by the caller.
{
int i;
const SScalableStats &Stats = GetScaledStats(ItemCtx);
// If we require a higher level to repair
if (GetRepairTech() != Stats.iLevel)
retList->Insert(SDisplayAttribute(attribNeutral, strPatternSubst(CONSTLIT("repair level %d"), GetRepairTech())));
// Radiation
if (Stats.fRadiationImmune)
{
if (Stats.iLevel < RADIATION_IMMUNE_LEVEL)
retList->Insert(SDisplayAttribute(attribPositive, CONSTLIT("radiation immune")));
}
else if (Stats.iLevel >= RADIATION_IMMUNE_LEVEL)
retList->Insert(SDisplayAttribute(attribNegative, CONSTLIT("radiation vulnerable")));
// If we're immune to blinding/EMP/device damage, then collapse
// it all under a single entry
bool bCheckedBlind = false;
bool bCheckedEMP = false;
bool bCheckedDevice = false;
if ((Stats.iBlindingDamageAdj == 0)
&& (Stats.iEMPDamageAdj == 0)
&& (Stats.iDeviceDamageAdj < 100))
{
if (Stats.iLevel < DEVICE_DAMAGE_IMMUNE_LEVEL)
retList->Insert(SDisplayAttribute(attribPositive, CONSTLIT("ionize immune")));
bCheckedBlind = true;
bCheckedEMP = true;
bCheckedDevice = true;
}
// Blindness
if (!bCheckedBlind)
{
if (Stats.iBlindingDamageAdj == 0)
{
if (Stats.iLevel < BLIND_IMMUNE_LEVEL)
retList->Insert(SDisplayAttribute(attribPositive, CONSTLIT("blind immune")));
}
else if (Stats.iBlindingDamageAdj < 100)
{
if (Stats.iLevel < BLIND_IMMUNE_LEVEL)
retList->Insert(SDisplayAttribute(attribPositive, CONSTLIT("blind resistant")));
else
retList->Insert(SDisplayAttribute(attribNegative, CONSTLIT("blind vulnerable")));
}
else if (Stats.iLevel >= BLIND_IMMUNE_LEVEL)
retList->Insert(SDisplayAttribute(attribNegative, CONSTLIT("blind vulnerable")));
}
// EMP
if (!bCheckedEMP)
{
if (Stats.iEMPDamageAdj == 0)
{
if (Stats.iLevel < EMP_IMMUNE_LEVEL)
retList->Insert(SDisplayAttribute(attribPositive, CONSTLIT("EMP immune")));
}
else if (Stats.iEMPDamageAdj < 100)
{
if (Stats.iLevel < EMP_IMMUNE_LEVEL)
retList->Insert(SDisplayAttribute(attribPositive, CONSTLIT("EMP resistant")));
else
retList->Insert(SDisplayAttribute(attribNegative, CONSTLIT("EMP vulnerable")));
}
else if (Stats.iLevel >= EMP_IMMUNE_LEVEL)
retList->Insert(SDisplayAttribute(attribNegative, CONSTLIT("EMP vulnerable")));
}
// Device damage
if (!bCheckedDevice)
{
if (Stats.iDeviceDamageAdj < 100)
{
if (Stats.iLevel < DEVICE_DAMAGE_IMMUNE_LEVEL)
retList->Insert(SDisplayAttribute(attribPositive, CONSTLIT("device protect")));
}
else if (Stats.iLevel >= DEVICE_DAMAGE_IMMUNE_LEVEL)
retList->Insert(SDisplayAttribute(attribNegative, CONSTLIT("device vulnerable")));
}
// Disintegration
if (Stats.fDisintegrationImmune)
{
if (Stats.iLevel < DISINTEGRATION_IMMUNE_LEVEL)
retList->Insert(SDisplayAttribute(attribPositive, CONSTLIT("disintegration immune")));
}
else if (Stats.iLevel >= DISINTEGRATION_IMMUNE_LEVEL)
retList->Insert(SDisplayAttribute(attribNegative, CONSTLIT("disintegration vulnerable")));
// Shatter
if (Stats.fShatterImmune)
{
if (Stats.iLevel < SHATTER_IMMUNE_LEVEL)
retList->Insert(SDisplayAttribute(attribPositive, CONSTLIT("shatter immune")));
}
else if (Stats.iLevel >= SHATTER_IMMUNE_LEVEL)
retList->Insert(SDisplayAttribute(attribNegative, CONSTLIT("shatter vulnerable")));
// Shield interference
if (m_fShieldInterference)
retList->Insert(SDisplayAttribute(attribNegative, CONSTLIT("no shields")));
// Regen
switch (Stats.iRegenType)
{
case regenNone:
break;
case regenSolar:
retList->Insert(SDisplayAttribute(attribPositive, CONSTLIT("photo-regen")));
break;
default:
retList->Insert(SDisplayAttribute(attribPositive, CONSTLIT("regen")));
break;
}
// Decay
if (!Stats.Decay.IsEmpty())
retList->Insert(SDisplayAttribute(attribNegative, CONSTLIT("decay")));
// Distribution
if (!Stats.Distribute.IsEmpty())
retList->Insert(SDisplayAttribute(attribPositive, CONSTLIT("distributing")));
// Solar power
if (m_fPhotoRecharge)
retList->Insert(SDisplayAttribute(attribPositive, CONSTLIT("solar")));
// Per damage-type bonuses
for (i = 0; i < damageCount; i++)
{
if (m_Reflective.InSet((DamageTypes)i))
retList->Insert(SDisplayAttribute(attribPositive, strPatternSubst(CONSTLIT("%s reflect"), GetDamageShortName((DamageTypes)i))));
}
}
bool CArmorClass::AccumulateEnhancements (CItemCtx &ItemCtx, CInstalledDevice *pTarget, TArray<CString> &EnhancementIDs, CItemEnhancementStack *pEnhancements)
// AccumulateEnhancements
//
// Adds enhancements to installed devices
{
// See if we give HP bonus to devices
if (m_iDeviceBonus != 0)
{
CInstalledArmor *pArmor = ItemCtx.GetArmor();
CSpaceObject *pSource = ItemCtx.GetSource();
// If the target item does not match our criteria, then no enhancement
if (pSource
&& pTarget
&& !pSource->GetItemForDevice(pTarget).MatchesCriteria(m_DeviceCriteria))
return false;
// If this enhancement type has already been applied, then nothing
if (!m_sEnhancementType.IsBlank()
&& EnhancementIDs.Find(m_sEnhancementType))
return false;
// Add HP bonus enhancements
pEnhancements->InsertHPBonus(m_iDeviceBonus);
if (!m_sEnhancementType.IsBlank())
EnhancementIDs.Insert(m_sEnhancementType);
return true;
}
return false;
}
bool CArmorClass::AccumulatePerformance (CItemCtx &ItemCtx, SShipPerformanceCtx &Ctx) const
// AccumulatePerformance
//
// Adds performance improvements (if any) to the ship performance context.
// Returns TRUE if any improvements were added.
{
int i;
bool bModified = false;
CSpaceObject *pSource = ItemCtx.GetSource();
CInstalledArmor *pArmor = ItemCtx.GetArmor();
const CItemEnhancementStack &Enhancements = ItemCtx.GetEnhancements();
// Keep track of armor so that we can adjust ship speed
Ctx.Armor.Insert(ItemCtx);
// Adjust max speed.
CArmorSystem *pArmorSet;
if (m_iMaxSpeedInc
&& pSource
&& pArmor
&& pArmor->IsPrime()
&& (pArmorSet = pSource->GetArmorSystem())
&& pArmorSet->GetSegmentCount() > 0)
{
// Count how many armor segments of this type
int iCount = 0;
for (i = 0; i < pArmorSet->GetSegmentCount(); i++)
if (pArmorSet->GetSegment(i).GetClass() == pArmor->GetClass())
iCount++;
// Compute the fraction of segments that are this type
Metric rSetFraction = (Metric)iCount / (Metric)pArmorSet->GetSegmentCount();
// Prorate the speed bonud
int iSpeed = mathRound(m_iMaxSpeedInc * rSetFraction);
if (iSpeed != 0)
{
Ctx.DriveDesc.AddMaxSpeed(iSpeed * LIGHT_SECOND / 100.0);
// Set the maximum speed
if (m_iMaxSpeedLimit == -1)
Ctx.rMaxSpeedLimit = LIGHT_SPEED;
else
Ctx.rMaxSpeedLimit = Max(Ctx.rMaxSpeedLimit, m_iMaxSpeedLimit * LIGHT_SPEED / 100.0);
}
}
// Shield interference
if (m_fShieldInterference || Enhancements.IsShieldInterfering())
{
Ctx.bShieldInterference = true;
bModified = true;
}
// Done
return bModified;
}
void CArmorClass::AddTypesUsed (TSortMap<DWORD, bool> *retTypesUsed)
// AddTypesUsed
//
// Adds types used by this class
{
}
ALERROR CArmorClass::BindScaledParams (SDesignLoadCtx &Ctx)
// BindScaledParams
//
// Bind scaled parameters
{
ALERROR error;
int i;
if (m_pScalable == NULL)
return NOERROR;
for (i = 0; i < m_iScaledLevels - 1; i++)
{
SScalableStats &Stats = m_pScalable[i];
if (error = Stats.DamageAdj.Bind(Ctx, g_pUniverse->GetArmorDamageAdj(Stats.iLevel)))
return error;
if (error = Stats.RepairCost.Bind(Ctx))
return error;
if (error = Stats.InstallCost.Bind(Ctx))
return error;
}
return NOERROR;
}
void CArmorClass::CalcAdjustedDamage (CItemCtx &ItemCtx, SDamageCtx &Ctx)
// CalcAdjustedDamage
//
// Initializes Ctx.iArmorDamage to account for damage type adjustments, etc.
{
CInstalledArmor *pArmor = ItemCtx.GetArmor();
// Adjust for special armor damage:
//
// <0 = 2.5x damage
// 0 = 2x damage
// 1 = 1.5x damage
// 2 = 1.25x damage
// >2 = 1x damage
int iDamageLevel = Ctx.Damage.GetArmorDamageLevel();
if (iDamageLevel > 0)
Ctx.iArmorDamage = mathAdjust(Ctx.iDamage, CalcArmorDamageAdj(ItemCtx, Ctx.Damage));
else
Ctx.iArmorDamage = Ctx.iDamage;
// Adjust for damage type
int iDamageAdj = GetDamageAdj(ItemCtx, Ctx.Damage);
Ctx.iArmorDamage = mathAdjust(Ctx.iArmorDamage, iDamageAdj);
}
int CArmorClass::CalcArmorDamageAdj (CItemCtx &ItemCtx, const DamageDesc &Damage) const
// CalcArmorDamageAdj
//
// Adjust for special armor damage:
//
// <0 = 2.5x damage
// 0 = 2x damage
// 1 = 1.5x damage
// 2 = 1.25x damage
// >2 = 1x damage
{
int iDamageLevel = Damage.GetArmorDamageLevel();
if (iDamageLevel <= 0)
return 100;
int iDiff = m_pItemType->GetLevel(ItemCtx) - iDamageLevel;
switch (iDiff)
{
case 0:
return 200;
case 1:
return 150;
case 2:
return 125;
default:
if (iDiff < 0)
return 250;
else
return 100;
}
}
int CArmorClass::CalcAverageRelativeDamageAdj (CItemCtx &ItemCtx)
// CalcAverageRelativeDamageAdj
//
// Compares this armor against standard damage adj for the level and returns
// the average damage adj relative to the standard.
{
int i;
Metric rTotalAdj = 0.0;
int iCount = 0;
int iArmorLevel = m_pItemType->GetLevel(ItemCtx);
for (i = damageLaser; i < damageCount; i++)
{
// If this damage type is within two levels of the armor level,
// then we include it in our calculations.
int iDamageLevel = ::GetDamageTypeLevel((DamageTypes)i);
if (iArmorLevel < iDamageLevel + 5
&& iArmorLevel > iDamageLevel - 3)
{
int iStdAdj = GetStdDamageAdj(iArmorLevel, (DamageTypes)i);
int iDamageAdj = GetDamageAdj(ItemCtx, (DamageTypes)i);
rTotalAdj += (iStdAdj > 0.0 ? (Metric)iDamageAdj * 100.0 / iStdAdj : 1000.0);
iCount++;
}
}
// Return average
return (iCount > 0 ? (int)((rTotalAdj / iCount) + 0.5) : 100);
}
int CArmorClass::CalcBalance (CItemCtx &ItemCtx, SBalance &retBalance) const
// CalcBalance
//
// Determines whether the given item is balanced for its level. Negative numbers
// mean the item is underpowered. Positive numbers mean the item is overpowered.
{
// Initialize
const SScalableStats &Stats = GetScaledStats(ItemCtx);
retBalance.iLevel = Stats.iLevel;
// Figure out how may HPs standard armor at this level should have.
const SStdStats &StdStats = GetStdStats(retBalance.iLevel);
// Compute the number of balance points (BP) of the damage. +100 = double
// HP relative to standard. -100 = half HP relative to standard.
retBalance.rHP = (int)GetMaxHP(ItemCtx, true);
retBalance.rHPBalance = 100.0 * mathLog2(retBalance.rHP / (Metric)StdStats.iHP);
retBalance.rBalance = retBalance.rHPBalance;
// Calculate the balance contribution of damage adjustment
retBalance.rDamageAdj = CalcBalanceDamageAdj(ItemCtx, Stats);
retBalance.rBalance += retBalance.rDamageAdj;
retBalance.rDamageEffectAdj = CalcBalanceDamageEffectAdj(ItemCtx, Stats);
retBalance.rBalance += retBalance.rDamageEffectAdj;
// Calculate regeneration/decay/etc.
retBalance.rRegen = CalcBalanceRegen(ItemCtx, Stats);
retBalance.rBalance += retBalance.rRegen;
// Repair tech
retBalance.rRepairAdj = CalcBalanceRepair(ItemCtx, Stats);
retBalance.rBalance += retBalance.rRepairAdj;
// If we have an armor complete bonus, we add a penalty to balance.
if (m_iArmorCompleteBonus)
{
retBalance.rArmorComplete = ARMOR_COMPLETE_BALANCE_ADJ * 100.0 * mathLog2((Metric)(m_iArmorCompleteBonus + StdStats.iHP) / (Metric)StdStats.iHP);
retBalance.rBalance += retBalance.rArmorComplete;
}
else
retBalance.rArmorComplete = 0.0;
// Stealth
if (m_iStealth >= 12)
retBalance.rStealth = 4.0 * STEALTH_BALANCE_BONUS;
else if (m_iStealth >= 10)
retBalance.rStealth = 3.0 * STEALTH_BALANCE_BONUS;
else if (m_iStealth >= 8)
retBalance.rStealth = 2.0 * STEALTH_BALANCE_BONUS;
else if (m_iStealth >= 6)
retBalance.rStealth = 1.0 * STEALTH_BALANCE_BONUS;
else
retBalance.rStealth = 0.0;
retBalance.rBalance += retBalance.rStealth;
// Power use
retBalance.rPowerUse = CalcBalancePower(ItemCtx, Stats);
retBalance.rBalance += retBalance.rPowerUse;
// Speed adjustment
retBalance.rSpeedAdj = MAX_SPEED_BALANCE_BONUS * m_iMaxSpeedInc;
retBalance.rBalance += retBalance.rSpeedAdj;
// Special features
retBalance.rDeviceBonus = CalcBalanceSpecial(ItemCtx, Stats);
retBalance.rBalance += retBalance.rDeviceBonus;
// Mass
retBalance.rMass = CalcBalanceMass(ItemCtx, Stats);
retBalance.rBalance += retBalance.rMass;
// Cost
Metric rCost = (Metric)CEconomyType::ExchangeToCredits(m_pItemType->GetCurrencyAndValue(ItemCtx, true));
Metric rCostDelta = 100.0 * (rCost - StdStats.iCost) / (Metric)StdStats.iCost;
retBalance.rCost = BALANCE_COST_RATIO * rCostDelta;
retBalance.rBalance += retBalance.rCost;
return (int)retBalance.rBalance;
}
Metric CArmorClass::CalcBalanceDamageAdj (CItemCtx &ItemCtx, const SScalableStats &Stats) const
// CalcBalanceDamageAdj
//
// Calculates the balance contribution of damage adjustment. 0 = same as
// standard for level.
{
DamageTypes iDamage;
// Loop over all damage types and accumulate balance adjustments.
Metric rTotalBalance = 0.0;
for (iDamage = damageLaser; iDamage < damageCount; iDamage = (DamageTypes)(iDamage + 1))
{
int iAdj;
int iDefaultAdj;
Stats.DamageAdj.GetAdjAndDefault(iDamage, &iAdj, &iDefaultAdj);
// Compare the adjustment and the standard adjustment. [We treat 0
// as 1 to avoid infinity.]
Metric rBalance = (100.0 * mathLog2((Metric)Max(1, iDefaultAdj) / (Metric)Max(1, iAdj)));
if (rBalance > BALANCE_MAX_DAMAGE_ADJ)
rBalance = BALANCE_MAX_DAMAGE_ADJ;
else if (rBalance < -BALANCE_MAX_DAMAGE_ADJ)
rBalance = -BALANCE_MAX_DAMAGE_ADJ;
// If we reflect this damage, adjust balance
if (m_Reflective.InSet(iDamage))
rBalance += REFLECTION_BALANCE_BONUS;
// Adjust the based on how common this damage type is at the given
// armor level.
rBalance *= CDamageAdjDesc::GetDamageTypeFraction(Stats.iLevel, iDamage);
// Accumulate
rTotalBalance += rBalance;
}
// Done
return rTotalBalance;
}
Metric CArmorClass::CalcBalanceDamageEffectAdj (CItemCtx &ItemCtx, const SScalableStats &Stats) const
// CalcBalanceDamageEffectAdj
//
// Return balance based on immunity/vulnerability to special damage effects.
{
Metric rBalance = 0.0;
// Immune/vulnerable to radiation?
if (Stats.fRadiationImmune)
{
if (Stats.iLevel < RADIATION_IMMUNE_LEVEL)
rBalance += RADIATION_IMMUNE_BALANCE_BONUS;
}
else if (Stats.iLevel >= RADIATION_IMMUNE_LEVEL)
rBalance += RADIATION_VULNERABLE_BALANCE_BONUS;
// Immune/vulnerable to blinding?
if (Stats.iBlindingDamageAdj < 50)
{
if (Stats.iLevel < BLIND_IMMUNE_LEVEL)
rBalance += BLIND_IMMUNE_BALANCE_BONUS;
}
else if (Stats.iLevel >= BLIND_IMMUNE_LEVEL)
rBalance += BLIND_VULNERABLE_BALANCE_BONUS;
// Immune/vulnerable to EMP?
if (Stats.iEMPDamageAdj < 50)
{
if (Stats.iLevel < EMP_IMMUNE_LEVEL)
rBalance += EMP_IMMUNE_BALANCE_BONUS;
}
else if (Stats.iLevel >= EMP_IMMUNE_LEVEL)
rBalance += EMP_VULNERABLE_BALANCE_BONUS;
// Immune/vulnerable to device damage?
if (Stats.iDeviceDamageAdj < 50)
{
if (Stats.iLevel < DEVICE_DAMAGE_IMMUNE_LEVEL)
rBalance += DEVICE_DAMAGE_IMMUNE_BALANCE_BONUS;
}
else if (Stats.iLevel >= DEVICE_DAMAGE_IMMUNE_LEVEL)
rBalance += DEVICE_DAMAGE_VULNERABLE_BALANCE_BONUS;
// Immune/vulnerable to disintegration?
if (Stats.fDisintegrationImmune)
{
if (Stats.iLevel < DISINTEGRATION_IMMUNE_LEVEL)
rBalance += DISINTEGRATION_IMMUNE_BALANCE_BONUS;
}
else if (Stats.iLevel >= DISINTEGRATION_IMMUNE_LEVEL)
rBalance += DISINTEGRATION_VULNERABLE_BALANCE_BONUS;
// Immune/vulnerable to shatter?
if (Stats.fShatterImmune)
{
if (Stats.iLevel < SHATTER_IMMUNE_LEVEL)
rBalance += SHATTER_IMMUNE_BALANCE_BONUS;
}
else if (Stats.iLevel >= SHATTER_IMMUNE_LEVEL)
rBalance += SHATTER_VULNERABLE_BALANCE_BONUS;
return rBalance;
}
Metric CArmorClass::CalcBalanceMass (CItemCtx &ItemCtx, const SScalableStats &Stats) const
// CalcBalanceMass
//
// Calculate balance from armor mass
{
// Mass in metric tons.
Metric rMass = CItem(m_pItemType, 1).GetMass();
if (rMass == 0.0)
return 0.0;
// Because this is an x^2 curve, we need a limit on mass or else we will start
// to curve up (more mass = bonus, which we don't want).
rMass = Min(rMass, MASS_BALANCE_LIMIT);
// This polynomial generates a balance based on mass.
return MASS_BALANCE_ADJ * ((MASS_BALANCE_K2 * rMass * rMass) + MASS_BALANCE_K1 * rMass + MASS_BALANCE_K0);
}
Metric CArmorClass::CalcBalancePower (CItemCtx &ItemCtx, const SScalableStats &Stats) const
// CalcBalancePower
//
// Calculate balance from consumption/production of power.
{
Metric rTotalBalance = 0.0;
if (m_iPowerUse)
{
// Compare power consumption to what an average shield requires.
rTotalBalance += POWER_USE_BALANCE_ADJ * (Metric)m_iPowerUse / CShieldClass::GetStdPower(Stats.iLevel);
}