Skip to content

Commit d6d43de

Browse files
committed
Make vehicle critical handling use opaque state
1 parent 24a3081 commit d6d43de

6 files changed

Lines changed: 48 additions & 33 deletions

File tree

src/btech/combat/crit_api.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ int handleWeaponCrit(Mech *attacker, Mech *wounded, int hitloc, int critHit,
2020
int critType, int LOS);
2121
void HandleVTOLCrit(Mech *wounded, Mech *attacker, int LOS, int hitloc,
2222
int num);
23-
void DestroyMainWeapon(Mech *mech);
23+
void mech_main_weapon_destroy(Mech *mech);
2424
void JamMainWeapon(Mech *mech);
2525
void pickRandomWeapon(Mech *objMech, int wLoc, int *critNum, int wIgnoreJams);
2626
void limitSpeedToCruise(Mech *objMech);
@@ -47,10 +47,10 @@ void DoVTOLRotorDestroyedCrit(Mech *objMech, Mech *objAttacker, int LOS);
4747
void StartVTOLCrash(Mech *objMech);
4848
void HandleAdvFasaVehicleCrit(Mech *wounded, Mech *attacker, int LOS,
4949
int hitloc, int num);
50-
void HandleFasaVehicleCrit(Mech *wounded, Mech *attacker, int LOS, int hitloc,
51-
int num);
52-
void HandleVehicleCrit(Mech *wounded, Mech *attacker, int LOS, int hitloc,
53-
int num);
50+
void mech_fasa_vehicle_critical_handle(Mech *wounded, Mech *attacker, int LOS,
51+
int hitloc, int num);
52+
void mech_vehicle_critical_handle(Mech *wounded, Mech *attacker, int LOS,
53+
int hitloc, int num);
5454
int HandleMechCrit(Mech *wounded, Mech *attacker, int LOS, int hitloc,
5555
int critHit, int critType, int critData);
5656
void mech_critical_handle(Mech *wounded, Mech *attacker, int LOS, int hitloc,

src/btech/combat/crit_dispatch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ void mech_critical_handle(Mech *wounded, Mech *attacker, int LOS, int hitloc,
8484
return;
8585
} else if (!btech_context_uses_fasa_criticals(context)) {
8686
for (i = 0; i < num; i++)
87-
HandleVehicleCrit(wounded, attacker, LOS, hitloc, num);
87+
mech_vehicle_critical_handle(wounded, attacker, LOS, hitloc, num);
8888
return;
8989
} else if (btech_context_uses_fasa_criticals(context)) {
9090
for (i = 0; i < num; i++)
91-
HandleFasaVehicleCrit(wounded, attacker, LOS, hitloc, num);
91+
mech_fasa_vehicle_critical_handle(wounded, attacker, LOS, hitloc, num);
9292
return;
9393
}
9494
}

src/btech/combat/crit_vehicle_dispatch.c

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,24 @@
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"
2928
#include "mech_combat_misc_api.h"
29+
#include "mech_condition_api.h"
3030
#include "mech_damage_api.h"
3131
#include "mech_enhanced_criticals_api.h"
32+
#include "mech_equipment_api.h"
3233
#include "mech_events.h"
3334
#include "mech_events_api.h"
35+
#include "mech_identity_api.h"
3436
#include "mech_lifecycle.h"
35-
#include "mech_macros.h"
3637
#include "mech_move_api.h"
3738
#include "mech_notify.h"
3839
#include "mech_notify_api.h"
3940
#include "mech_pickup_api.h"
4041
#include "mech_sensor.h"
42+
#include "mech_specification_api.h"
4143
#include "mech_tag_api.h"
4244
#include "mech_tech_commands_api.h"
4345
#include "mech_update_api.h"
@@ -50,8 +52,9 @@
5052
#include "mux/support/formatting.h"
5153
#include "random.h"
5254
#include "registry_api.h"
55+
#include "section_types.h"
5356

54-
void DestroyMainWeapon(Mech *mech) {
57+
void mech_main_weapon_destroy(Mech *mech) {
5558
unsigned char weaparray[MAX_WEAPS_SECTION];
5659
unsigned char weapdata[MAX_WEAPS_SECTION];
5760
int critical[MAX_WEAPS_SECTION];
@@ -64,16 +67,17 @@ void DestroyMainWeapon(Mech *mech) {
6467
int critfound = 0;
6568
unsigned char maxtype = 0;
6669
int firstCrit = 0;
70+
BtechContext *context = mech_context(mech);
6771

6872
for (loop = 0; loop < NUM_SECTIONS; loop++) {
69-
if (SectIsDestroyed(mech, loop))
73+
if (mech_section_is_destroyed(mech, loop))
7074
continue;
71-
count = FindWeapons(mech, loop, weaparray, weapdata, critical);
75+
count = FindWeapons_Advanced(mech, loop, weaparray, weapdata, critical, 1);
7276
if (count > 0) {
7377
for (ii = 0; ii < count; ii++) {
74-
if (!PartIsBroken(mech, loop, critical[ii])) {
78+
if (!mech_critical_is_broken(mech, loop, critical[ii])) {
7579
/* tempcrit = GetWeaponCrits(mech, weaparray[ii]); */
76-
tempcrit = (int)btech_random_i31(&mech->xcode.context->random);
80+
tempcrit = (int)btech_context_random_i31(context);
7781
if (tempcrit > maxcrit) {
7882
critfound = 1;
7983
maxcrit = tempcrit;
@@ -93,13 +97,15 @@ void DestroyMainWeapon(Mech *mech) {
9397
}
9498
}
9599

96-
void HandleFasaVehicleCrit(Mech *wounded, Mech *attacker, int LOS, int hitloc,
97-
int num) {
98-
if (MechMove(wounded) == MOVE_NONE)
100+
void mech_fasa_vehicle_critical_handle(Mech *wounded, Mech *attacker, int LOS,
101+
int hitloc, int num) {
102+
BtechContext *context = mech_context(wounded);
103+
104+
if (mech_movement_type(wounded) == MOVE_NONE)
99105
return;
100106

101107
mech_notify(wounded, MECHALL, "[fg=yellow bold]CRITICAL HIT![reset]");
102-
switch (btech_random_range(wounded->xcode.context, 0, 5)) {
108+
switch (btech_random_range(context, 0, 5)) {
103109
case 0:
104110
/* Crew stunned for one turn...treat like a head hit */
105111
headhitmwdamage(wounded, attacker, 1);
@@ -136,37 +142,40 @@ void HandleFasaVehicleCrit(Mech *wounded, Mech *attacker, int LOS, int hitloc,
136142
if (wounded != attacker)
137143
mech_los_broadcast(wounded, "'s power plant suddenly explodes!");
138144
DestroyMech(wounded, attacker, 1, KILL_TYPE_POWERPLANT);
139-
if (!(MechSections(wounded)[BSIDE].config & CASE_TECH))
145+
if (!mech_section_has_special(wounded, BSIDE, CASE_TECH))
140146
explode_unit(wounded, attacker);
141147
else
142148
DestroySection(wounded, attacker, LOS, BSIDE);
143149
break;
144150
}
145151
}
146152

147-
void HandleVehicleCrit(Mech *wounded, Mech *attacker, int LOS, int hitloc,
148-
int num) {
149-
if (MechMove(wounded) == MOVE_NONE)
153+
void mech_vehicle_critical_handle(Mech *wounded, Mech *attacker, int LOS,
154+
int hitloc, int num) {
155+
BtechContext *context = mech_context(wounded);
156+
MechConditionSummary condition = mech_condition_summary(wounded);
157+
158+
if (mech_movement_type(wounded) == MOVE_NONE)
150159
return;
151160
if (hitloc == TURRET) {
152-
if (btech_random_range(wounded->xcode.context, 1, 3) == 2) {
153-
if (!(MechTankCritStatus(wounded) & TURRET_LOCKED)) {
161+
if (btech_random_range(context, 1, 3) == 2) {
162+
if (!condition.turret_locked) {
154163
mech_notify(wounded, MECHALL, "[fg=yellow bold]CRITICAL HIT![reset]");
155-
MechTankCritStatus(wounded) |= TURRET_LOCKED;
164+
mech_turret_locked_set(wounded, true);
156165
mech_notify(wounded, MECHALL,
157166
"Your turret takes a direct hit and locks up!");
158167
}
159168
return;
160169
}
161170
} else
162-
switch (btech_random_range(wounded->xcode.context, 1, 10)) {
171+
switch (btech_random_range(context, 1, 10)) {
163172
case 1:
164173
case 2:
165174
case 3:
166175
case 4:
167-
if (!Fallen(wounded)) {
176+
if (!condition.fallen) {
168177
mech_notify(wounded, MECHALL, "[fg=yellow bold]CRITICAL HIT![reset]");
169-
switch (MechMove(wounded)) {
178+
switch (mech_movement_type(wounded)) {
170179
case MOVE_TRACK:
171180
mech_notify(wounded, MECHALL, "One of your tracks is damaged!");
172181
break;
@@ -187,9 +196,9 @@ void HandleVehicleCrit(Mech *wounded, Mech *attacker, int LOS, int hitloc,
187196
return;
188197
break;
189198
case 5:
190-
if (!Fallen(wounded)) {
199+
if (!condition.fallen) {
191200
mech_notify(wounded, MECHALL, "[fg=yellow bold]CRITICAL HIT![reset]");
192-
switch (MechMove(wounded)) {
201+
switch (mech_movement_type(wounded)) {
193202
case MOVE_TRACK:
194203
mech_notify(
195204
wounded, MECHALL,
@@ -218,7 +227,7 @@ void HandleVehicleCrit(Mech *wounded, Mech *attacker, int LOS, int hitloc,
218227
break;
219228
}
220229
mech_notify(wounded, MECHALL, "[fg=yellow bold]CRITICAL HIT![reset]");
221-
switch (btech_random_range(wounded->xcode.context, 0, 5)) {
230+
switch (btech_random_range(context, 0, 5)) {
222231
case 0:
223232
/* Crew stunned for one turn...treat like a head hit */
224233
headhitmwdamage(wounded, attacker, 1);

src/btech/combat/mech_hitloc_fasa_vtol_naval.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ int fasa_vtol_naval_hit_location(Mech *mech, int hitGroup, int *iscritical,
4141
break;
4242
case 9:
4343
/* Destroy Main Weapon but do not destroy armor */
44-
DestroyMainWeapon(mech);
44+
mech_main_weapon_destroy(mech);
4545
hitloc = 0;
4646
break;
4747
case 10:
@@ -79,7 +79,7 @@ int fasa_vtol_naval_hit_location(Mech *mech, int hitGroup, int *iscritical,
7979
break;
8080
case 9:
8181
/* Destroy Main Weapon but do not destroy armor */
82-
DestroyMainWeapon(mech);
82+
mech_main_weapon_destroy(mech);
8383
break;
8484
case 10:
8585
case 11:

src/btech/core/context.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,11 @@ void btech_context_hit_roll_record(BtechContext *context, int roll) {
268268
context->random.statistics.total_hit_rolls++;
269269
}
270270

271+
long btech_context_random_i31(BtechContext *context) {
272+
assert(context != nullptr);
273+
return btech_random_i31(&context->random);
274+
}
275+
271276
int btech_context_event_data_count(const BtechContext *context, int event_type,
272277
intptr_t event_data) {
273278
assert(context != nullptr);

src/btech/include/btech/context.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ int btech_context_stagger_interval(const BtechContext *context);
9494
bool btech_context_stagger_uses_tonnage(const BtechContext *context);
9595
int btech_context_event_tick(const BtechContext *context);
9696
void btech_context_hit_roll_record(BtechContext *context, int roll);
97+
long btech_context_random_i31(BtechContext *context);
9798
int btech_context_event_data_count(const BtechContext *context, int event_type,
9899
intptr_t event_data);
99100
time_t btech_context_now(const BtechContext *context);

0 commit comments

Comments
 (0)