Skip to content

Commit 24a3081

Browse files
committed
Make critical dispatch use opaque unit state
1 parent 0ed88a5 commit 24a3081

6 files changed

Lines changed: 46 additions & 37 deletions

File tree

src/btech/autopilot/autopilot_radio.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "btech_channel.h"
3131
#include "btech_event.h"
3232
#include "command_handlers_api.h"
33+
#include "legacy_macros.h"
3334
#include "map.h"
3435
#include "map_terrain.h"
3536
#include "mech_classification_api.h"

src/btech/autopilot/autopilot_radio_handlers.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "btech_channel.h"
3131
#include "btech_event.h"
3232
#include "command_handlers_api.h"
33+
#include "legacy_macros.h"
3334
#include "map.h"
3435
#include "map_terrain.h"
3536
#include "mech_events.h"

src/btech/combat/bsuit.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -606,11 +606,11 @@ void bsuit_attackleg(DbRef player, void *data, char *buffer) {
606606
switch (wCritRoll) {
607607
case 8:
608608
case 9:
609-
HandleCritical(target, mech, 1, wLegID, 1);
609+
mech_critical_handle(target, mech, 1, wLegID, 1);
610610
break;
611611
case 10:
612612
case 11:
613-
HandleCritical(target, mech, 1, wLegID, 2);
613+
mech_critical_handle(target, mech, 1, wLegID, 2);
614614
break;
615615
case 12:
616616
switch (wLegID) {
@@ -628,7 +628,7 @@ void bsuit_attackleg(DbRef player, void *data, char *buffer) {
628628
DestroySection(target, mech, 1, wLegID);
629629
[[fallthrough]];
630630
default:
631-
HandleCritical(target, mech, 1, wLegID, 3);
631+
mech_critical_handle(target, mech, 1, wLegID, 3);
632632
}
633633
break;
634634
default:

src/btech/combat/crit_api.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ void HandleVehicleCrit(Mech *wounded, Mech *attacker, int LOS, int hitloc,
5353
int num);
5454
int HandleMechCrit(Mech *wounded, Mech *attacker, int LOS, int hitloc,
5555
int critHit, int critType, int critData);
56-
void HandleCritical(Mech *wounded, Mech *attacker, int LOS, int hitloc,
57-
int num);
56+
void mech_critical_handle(Mech *wounded, Mech *attacker, int LOS, int hitloc,
57+
int num);
5858
void NormalizeArmActuatorCrits(Mech *objMech, int wLoc, int wCritType);
5959
void NormalizeLegActuatorCrits(Mech *objMech, int wLoc, int wCritType);
6060
void NormalizeLocActuatorCrits(Mech *objMech, int wLoc);

src/btech/combat/crit_dispatch.c

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,26 @@
2222
#include "failures.h"
2323
#include "map.h"
2424
#include "map_terrain.h"
25-
#include "mech.h"
2625
#include "mech_ammodump_api.h"
2726
#include "mech_c3_api.h"
2827
#include "mech_c3i_api.h"
28+
#include "mech_classification_api.h"
2929
#include "mech_combat_misc_api.h"
30+
#include "mech_condition_api.h"
3031
#include "mech_damage_api.h"
3132
#include "mech_enhanced_criticals_api.h"
33+
#include "mech_equipment_api.h"
3234
#include "mech_events.h"
3335
#include "mech_events_api.h"
36+
#include "mech_identity_api.h"
3437
#include "mech_lifecycle.h"
35-
#include "mech_macros.h"
3638
#include "mech_move_api.h"
3739
#include "mech_notify.h"
3840
#include "mech_notify_api.h"
3941
#include "mech_pickup_api.h"
4042
#include "mech_sensor.h"
43+
#include "mech_specification_api.h"
44+
#include "mech_status_types.h"
4145
#include "mech_tag_api.h"
4246
#include "mech_tech_commands_api.h"
4347
#include "mech_update_api.h"
@@ -50,46 +54,48 @@
5054
#include "mux/support/formatting.h"
5155
#include "random.h"
5256
#include "registry_api.h"
57+
#include "section_types.h"
5358

54-
void HandleCritical(Mech *wounded, Mech *attacker, int LOS, int hitloc,
55-
int num) {
59+
void mech_critical_handle(Mech *wounded, Mech *attacker, int LOS, int hitloc,
60+
int num) {
5661
int i;
5762
int critHit;
5863
int critType, critData;
5964
int count, index;
6065
int critList[NUM_CRITICALS];
66+
BtechContext *context = mech_context(wounded);
67+
MechConditionSummary condition = mech_condition_summary(wounded);
6168

62-
if (MechStatus(wounded) & COMBAT_SAFE)
69+
if (condition.combat_safe)
6370
return;
64-
if (MechSpecials(wounded) & CRITPROOF_TECH)
71+
if (mech_technology_flags(wounded) & CRITPROOF_TECH)
6572
return;
66-
if (MechType(wounded) == CLASS_MW &&
67-
btech_random_range(wounded->xcode.context, 1, 2) == 1)
73+
if (mech_class(wounded) == CLASS_MW && btech_random_range(context, 1, 2) == 1)
6874
return;
69-
if (MechType(wounded) != CLASS_MECH &&
70-
!wounded->xcode.context->configuration->btech_vcrit)
75+
if (mech_class(wounded) != CLASS_MECH &&
76+
!btech_context_vehicle_critical_mode(context))
7177
return;
72-
if (MechType(wounded) == CLASS_VEH_GROUND ||
73-
MechType(wounded) == CLASS_VEH_NAVAL) {
74-
if (wounded->xcode.context->configuration->btech_fasaadvvhlcrit) {
78+
if (mech_class(wounded) == CLASS_VEH_GROUND ||
79+
mech_class(wounded) == CLASS_VEH_NAVAL) {
80+
if (btech_context_uses_advanced_vehicle_criticals(context)) {
7581
for (i = 0; i < num; i++)
7682
HandleAdvFasaVehicleCrit(wounded, attacker, LOS, hitloc, num);
7783

7884
return;
79-
} else if (!wounded->xcode.context->configuration->btech_fasacrit) {
85+
} else if (!btech_context_uses_fasa_criticals(context)) {
8086
for (i = 0; i < num; i++)
8187
HandleVehicleCrit(wounded, attacker, LOS, hitloc, num);
8288
return;
83-
} else if (wounded->xcode.context->configuration->btech_fasacrit) {
89+
} else if (btech_context_uses_fasa_criticals(context)) {
8490
for (i = 0; i < num; i++)
8591
HandleFasaVehicleCrit(wounded, attacker, LOS, hitloc, num);
8692
return;
8793
}
8894
}
89-
if (IsDS(wounded))
95+
if (mech_is_dropship(wounded))
9096
return;
91-
if (MechType(wounded) == CLASS_VTOL) {
92-
if (wounded->xcode.context->configuration->btech_fasaadvvtolcrit) {
97+
if (mech_class(wounded) == CLASS_VTOL) {
98+
if (btech_context_uses_advanced_vtol_criticals(context)) {
9399
for (i = 0; i < num; i++)
94100
HandleAdvFasaVehicleCrit(wounded, attacker, LOS, hitloc, num);
95101

@@ -105,10 +111,11 @@ void HandleCritical(Mech *wounded, Mech *attacker, int LOS, int hitloc,
105111
count = 0;
106112
while (count == 0) {
107113
for (i = 0; i < NUM_CRITICALS; i++) {
108-
critType = GetPartType(wounded, hitloc, i);
109-
if (!PartIsDestroyed(wounded, hitloc, i) &&
110-
!PartIsDamaged(wounded, hitloc, i) && critType != EMPTY &&
111-
critType != Special(CASE) && critType != Special(FERRO_FIBROUS) &&
114+
critType = mech_critical_part_type(wounded, hitloc, i);
115+
if (!mech_critical_is_destroyed(wounded, hitloc, i) &&
116+
!mech_critical_is_damaged(wounded, hitloc, i) &&
117+
critType != EMPTY && critType != Special(CASE) &&
118+
critType != Special(FERRO_FIBROUS) &&
112119
critType != Special(STEALTH_ARMOR) &&
113120
critType != Special(HVY_FERRO_FIBROUS) &&
114121
critType != Special(LT_FERRO_FIBROUS) &&
@@ -124,11 +131,11 @@ void HandleCritical(Mech *wounded, Mech *attacker, int LOS, int hitloc,
124131
return;
125132
}
126133

127-
index = btech_random_range(wounded->xcode.context, 0, count - 1);
134+
index = btech_random_range(context, 0, count - 1);
128135
critHit = critList[index]; /* This one should be linear */
129136

130-
critType = GetPartType(wounded, hitloc, critHit);
131-
critData = GetPartData(wounded, hitloc, critHit);
137+
critType = mech_critical_part_type(wounded, hitloc, critHit);
138+
critData = mech_critical_data(wounded, hitloc, critHit);
132139

133140
if (HandleMechCrit(wounded, attacker, LOS, hitloc, critHit, critType,
134141
critData))

src/btech/combat/mech_armor_damage.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,16 +196,16 @@ int cause_armordamage(Mech *wounded, Mech *attacker, int LOS, int attackPilot,
196196
switch (r) {
197197
case 8:
198198
case 9:
199-
HandleCritical(wounded, attacker, LOS, hitloc, 1);
199+
mech_critical_handle(wounded, attacker, LOS, hitloc, 1);
200200
(*crits) += 1;
201201
break;
202202
case 10:
203203
case 11:
204-
HandleCritical(wounded, attacker, LOS, hitloc, 2);
204+
mech_critical_handle(wounded, attacker, LOS, hitloc, 2);
205205
(*crits) += 2;
206206
break;
207207
case 12:
208-
HandleCritical(wounded, attacker, LOS, hitloc, 3);
208+
mech_critical_handle(wounded, attacker, LOS, hitloc, 3);
209209
(*crits) += 3;
210210
break;
211211
default:
@@ -267,11 +267,11 @@ int cause_internaldamage(Mech *wounded, Mech *attacker, int LOS,
267267
switch (r) {
268268
case 8:
269269
case 9:
270-
HandleCritical(wounded, attacker, LOS, hitloc, 1);
270+
mech_critical_handle(wounded, attacker, LOS, hitloc, 1);
271271
break;
272272
case 10:
273273
case 11:
274-
HandleCritical(wounded, attacker, LOS, hitloc, 2);
274+
mech_critical_handle(wounded, attacker, LOS, hitloc, 2);
275275
break;
276276
case 12:
277277
if ((MechType(wounded) == CLASS_MECH) ||
@@ -297,11 +297,11 @@ int cause_internaldamage(Mech *wounded, Mech *attacker, int LOS,
297297
break;
298298
default:
299299
/* Ouch */
300-
HandleCritical(wounded, attacker, LOS, hitloc, 3);
300+
mech_critical_handle(wounded, attacker, LOS, hitloc, 3);
301301
break;
302302
}
303303
} else {
304-
HandleCritical(wounded, attacker, LOS, hitloc, 3);
304+
mech_critical_handle(wounded, attacker, LOS, hitloc, 3);
305305
}
306306

307307
break;

0 commit comments

Comments
 (0)