Skip to content

Commit b5916bc

Browse files
committed
refactor: eliminate clang-tidy diagnostics
1 parent f4ef59c commit b5916bc

526 files changed

Lines changed: 24137 additions & 13352 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.clang-tidy

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,7 @@ Checks: >
99
clang-analyzer-deadcode.*,
1010
cert-*-c,
1111
-cert-dcl37-c,
12-
bugprone-narrowing-conversions,
13-
bugprone-branch-clone,
14-
bugprone-suspicious-memory-comparison,
15-
bugprone-suspicious-realloc-usage,
16-
bugprone-suspicious-string-compare,
17-
bugprone-switch-missing-default-case,
18-
bugprone-undefined-memory-manipulation,
19-
bugprone-unused-return-value,
12+
bugprone-*,
2013
misc-include-cleaner
2114
WarningsAsErrors: '*'
2215
HeaderFilterRegex: '^.*/src/(mux|btech)/.*'

CMakeLists.txt

Lines changed: 88 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,90 @@ if(BUILD_TESTING)
405405
"${CMAKE_SOURCE_DIR}/src")
406406
add_test(NAME btech_random COMMAND btech_random_test)
407407

408+
add_executable(btech_weapon_failure_test
409+
tests/btech_weapon_failure.c
410+
${BTECH_SOURCE_DIR}/combat/mech_weapon_failure.c)
411+
target_compile_definitions(btech_weapon_failure_test PRIVATE BTECH_INTERNAL=1)
412+
target_link_libraries(btech_weapon_failure_test PRIVATE btmux_options)
413+
target_include_directories(btech_weapon_failure_test PRIVATE
414+
"${CMAKE_BINARY_DIR}/${BTECH_SOURCE_DIR}"
415+
"${CMAKE_BINARY_DIR}"
416+
${BTECH_PRIVATE_INCLUDE_DIRS}
417+
"${CMAKE_SOURCE_DIR}/src")
418+
add_test(NAME btech_weapon_failure COMMAND btech_weapon_failure_test)
419+
420+
add_executable(btech_ammunition_decrement_test
421+
tests/btech_ammunition_decrement.c
422+
${BTECH_SOURCE_DIR}/combat/mech_ammunition_decrement.c)
423+
target_compile_definitions(btech_ammunition_decrement_test
424+
PRIVATE BTECH_INTERNAL=1)
425+
target_compile_options(btech_ammunition_decrement_test
426+
PRIVATE -ffunction-sections)
427+
target_link_options(btech_ammunition_decrement_test
428+
PRIVATE -Wl,--gc-sections)
429+
target_link_libraries(btech_ammunition_decrement_test PRIVATE btmux_options)
430+
target_include_directories(btech_ammunition_decrement_test PRIVATE
431+
"${CMAKE_BINARY_DIR}/${BTECH_SOURCE_DIR}"
432+
"${CMAKE_BINARY_DIR}"
433+
${BTECH_PRIVATE_INCLUDE_DIRS}
434+
"${CMAKE_SOURCE_DIR}/src")
435+
add_test(NAME btech_ammunition_decrement
436+
COMMAND btech_ammunition_decrement_test)
437+
438+
add_executable(btech_ammunition_check_test
439+
tests/btech_ammunition_check.c
440+
${BTECH_SOURCE_DIR}/unit/mech_systems.c)
441+
target_compile_definitions(btech_ammunition_check_test
442+
PRIVATE BTECH_INTERNAL=1)
443+
target_compile_options(btech_ammunition_check_test
444+
PRIVATE -ffunction-sections)
445+
target_link_options(btech_ammunition_check_test
446+
PRIVATE -Wl,--gc-sections)
447+
target_link_libraries(btech_ammunition_check_test PRIVATE btmux_options)
448+
target_include_directories(btech_ammunition_check_test PRIVATE
449+
"${CMAKE_BINARY_DIR}/${BTECH_SOURCE_DIR}"
450+
"${CMAKE_BINARY_DIR}"
451+
${BTECH_PRIVATE_INCLUDE_DIRS}
452+
"${CMAKE_SOURCE_DIR}/src")
453+
add_test(NAME btech_ammunition_check COMMAND btech_ammunition_check_test)
454+
455+
add_executable(btech_normal_to_hit_test
456+
tests/btech_normal_to_hit.c
457+
${BTECH_SOURCE_DIR}/combat/mech_bth.c)
458+
target_compile_definitions(btech_normal_to_hit_test PRIVATE BTECH_INTERNAL=1)
459+
target_compile_options(btech_normal_to_hit_test PRIVATE -ffunction-sections)
460+
target_link_options(btech_normal_to_hit_test PRIVATE -Wl,--gc-sections)
461+
target_link_libraries(btech_normal_to_hit_test PRIVATE btmux_options m)
462+
target_include_directories(btech_normal_to_hit_test PRIVATE
463+
"${CMAKE_BINARY_DIR}/${BTECH_SOURCE_DIR}"
464+
"${CMAKE_BINARY_DIR}"
465+
${BTECH_PRIVATE_INCLUDE_DIRS}
466+
"${CMAKE_SOURCE_DIR}/src")
467+
add_test(NAME btech_normal_to_hit COMMAND btech_normal_to_hit_test)
468+
469+
add_executable(btech_damage_apply_test
470+
tests/btech_damage_apply.c
471+
${BTECH_SOURCE_DIR}/combat/mech_damage.c)
472+
target_compile_definitions(btech_damage_apply_test PRIVATE BTECH_INTERNAL=1)
473+
target_compile_options(btech_damage_apply_test PRIVATE -ffunction-sections)
474+
target_compile_options(btech_damage_apply_test PRIVATE
475+
-Wno-missing-prototypes -Wno-strict-prototypes)
476+
target_link_options(btech_damage_apply_test PRIVATE -Wl,--gc-sections)
477+
target_link_libraries(btech_damage_apply_test PRIVATE btmux_options)
478+
target_include_directories(btech_damage_apply_test PRIVATE
479+
"${CMAKE_BINARY_DIR}/${BTECH_SOURCE_DIR}"
480+
"${CMAKE_BINARY_DIR}"
481+
${BTECH_PRIVATE_INCLUDE_DIRS}
482+
"${CMAKE_SOURCE_DIR}/src")
483+
add_test(NAME btech_damage_apply COMMAND btech_damage_apply_test)
484+
485+
add_executable(checked_storage_test tests/checked_storage.c)
486+
target_link_libraries(checked_storage_test
487+
PRIVATE btmux_options btmux_checked_storage)
488+
target_include_directories(checked_storage_test PRIVATE
489+
"${CMAKE_SOURCE_DIR}/src")
490+
add_test(NAME checked_storage COMMAND checked_storage_test)
491+
408492
add_executable(btech_persistence_schema_test
409493
tests/btech_persistence_schema.c
410494
${BTECH_SOURCE_DIR}/persistence/schema.c)
@@ -640,7 +724,8 @@ if(BUILD_TESTING)
640724
add_test(NAME help_frontmatter_parse COMMAND help_frontmatter_parse_test)
641725

642726
add_executable(help_render_test tests/help_render.c
643-
${MUX_SOURCE_DIR}/help/help_render.c)
727+
${MUX_SOURCE_DIR}/help/help_render.c
728+
${MUX_SOURCE_DIR}/support/array_sort.c)
644729
target_link_libraries(help_render_test PRIVATE btmux_options cmark)
645730
target_include_directories(help_render_test PRIVATE
646731
"${CMAKE_BINARY_DIR}"
@@ -649,7 +734,8 @@ if(BUILD_TESTING)
649734

650735
add_executable(help_index_integration_test tests/help_index_integration.c
651736
${MUX_SOURCE_DIR}/help/help_frontmatter.c
652-
${MUX_SOURCE_DIR}/help/help_index.c)
737+
${MUX_SOURCE_DIR}/help/help_index.c
738+
${MUX_SOURCE_DIR}/support/array_sort.c)
653739
target_link_libraries(help_index_integration_test PRIVATE btmux_options tomlc17)
654740
target_include_directories(help_index_integration_test PRIVATE
655741
"${CMAKE_BINARY_DIR}"

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ It comes with a real-time combat system with AI, a unit repair system, economic
44
## Status
55

66
StompyMUX is an occasionally developed modernization fork of [BattletechMUX](https://sourceforge.net/projects/btonline-btech/).
7-
Our foundations are built from more than [three decades of contributions](./docs/content/en/docs/history.md).
7+
Our foundations are built from more than [three decades of contributions](./docs/content/docs/history.md).
88
While the features in this codebase are very well fleshed out, we may occasionally break things, including backwards compatibility!
99

1010
## Getting involved
1111

1212
Contributions are welcomed.
13-
See the [Contributing](./docs/content/en/docs/contributing.md) guide.
13+
See the [Contributing](./docs/content/docs/contributing.md) guide.
1414
Visit our [Discord server](https://discord.gg/TJzQByY2nC) to reach the rest of the developer community.
1515

1616
## Support

TODO

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## General hygeine
44

55
* Eliminate conditional compilation
6+
* .clang-format: Langauge=C instead of Cpp
67
* Doxygen comment all public functions in headers with @param[in] and @param[out]
78
* Doxygen comment all static and private functions?
89
* Look into clang-tidy/clangd readability-identifier-naming and VariableCase + FunctionCase
@@ -39,4 +40,8 @@
3940
* What is CharacterXpRanking?
4041
* Add `-fhardened` to CMake for mux and btech. May require disabling debug builds.
4142
* remove MechRuntimeState.unused
42-
* Replace CVS headers
43+
* Replace CVS headers
44+
* Unused terrain types?
45+
* Autopilot bug fixing and testing
46+
* Complete Autopilot placeholders
47+
* LOS bug fixing and testing

game/stompymux.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# From within this file, you can change much about the way your game behaves.
44
# Some directives are clearly labeled and described, others are not. Others
55
# aren't even listed in this file. For a complete list with descriptions,
6-
# please see docs/content/en/docs/configuration/stompymux-toml.md.
6+
# please see docs/content/docs/configuration/stompymux-toml.md.
77
# ----------------------------------------------------------------------------
88

99
# Include the stock command and flag aliases. Add local

justfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ stylua := env("STYLUA", "stylua")
99

1010
default: checks install
1111

12-
ci: check-mux-source-size fmt-check build test
12+
ci: check-mux-source-size fmt-check build test tidy-check
1313

1414
agent-checks: ci
1515

@@ -37,6 +37,9 @@ fmt-check: fmt-check-c fmt-check-lua
3737
tidy:
3838
{{run_clang_tidy}} -clang-tidy-binary {{clang_tidy}} -quiet -fix -p {{build_dir}} -j "$(nproc)" '^.*/src/(mux|btech)/.*[.]c$'
3939

40+
tidy-check:
41+
{{run_clang_tidy}} -clang-tidy-binary {{clang_tidy}} -quiet -p {{build_dir}} -j "$(nproc)" '^.*/src/(mux|btech)/.*[.]c$'
42+
4043
build:
4144
cmake -S . -B {{build_dir}} -DCMAKE_C_COMPILER=clang-22 -DCMAKE_BUILD_TYPE={{build_type}} -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
4245
cmake --build {{build_dir}} -j "$(nproc)"

src/btech/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ set(BTECH_SOURCES
55
autopilot/autopilot_navigation.c
66
autopilot/autopilot_pathfinding.c
77
autopilot/autopilot_autogun.c
8+
autopilot/autopilot_autogun_fire.c
89
autopilot/autopilot_sensor_policy.c
910
autopilot/autopilot_weapon_profile.c
1011
autopilot/autopilot_target_scoring.c
@@ -35,6 +36,7 @@ set(BTECH_SOURCES
3536
character/pcombat.c
3637
combat/artillery.c
3738
combat/bsuit.c
39+
combat/bsuit_swarm.c
3840
combat/bsuit_hide.c
3941
combat/crit.c
4042
combat/crit_weapons.c
@@ -51,7 +53,10 @@ set(BTECH_SOURCES
5153
combat/mech_bth_movement.c
5254
combat/mech_combat.c
5355
combat/mech_fire_command.c
56+
combat/mech_weapon_failure.c
57+
combat/mech_ammunition_decrement.c
5458
combat/mech_fire_resolution.c
59+
combat/mech_fire_preparation.c
5560
combat/mech_hit_resolution.c
5661
combat/mech_terrain_effects.c
5762
combat/mech_combat_misc.c
@@ -176,6 +181,7 @@ set(BTECH_SOURCES
176181
persistence/schema_v2.c
177182
persistence/snapshot_store.c
178183
persistence/snapshot_store_objects.c
184+
persistence/snapshot_store_auxiliary.c
179185
persistence/special_restore.c
180186
persistence/validation.c
181187
repair/mech_tech.c
@@ -202,10 +208,14 @@ set(BTECH_SOURCES
202208
scripting/registry_values.c
203209
scripting/value_catalog.c
204210
scripting/repair_map_values.c
211+
scripting/repair_damage_values.c
205212
scripting/unit_query_values.c
213+
scripting/unit_battle_value_values.c
206214
scripting/unit_query_reports.c
207215
scripting/unit_values.c
208216
scripting/world_values.c
217+
scripting/world_map_values.c
218+
scripting/world_part_cost_values.c
209219
sensors/los_trace.c
210220
sensors/mech_c3.c
211221
sensors/mech_c3_misc.c
@@ -230,6 +240,7 @@ set(BTECH_SOURCES
230240
ui/mech_maps.c
231241
ui/mech_lrs_map.c
232242
ui/mech_tactical_map.c
243+
ui/mech_tactical_overlays.c
233244
ui/mech_tactical_layout.c
234245
ui/mech_tactical_style.c
235246
ui/mech_tactical_command.c
@@ -287,6 +298,7 @@ set(BTECH_SOURCES
287298
unit/template_internals.c
288299
unit/template_inventory.c
289300
unit/template_load.c
301+
unit/template_load_helpers.c
290302
unit/template_legacy_load.c
291303
unit/template_registry.c
292304
unit/template_save.c)

src/btech/autopilot/ai_simulation.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "command_handlers_api.h"
1111
#include "equipment_types.h"
1212
#include "map_conditions_api.h"
13+
#include "map_coordinates.h"
1314
#include "map_terrain.h"
1415
#include "map_units_api.h"
1516
#include "mech_classification_api.h"
@@ -95,8 +96,13 @@ int ai_crash(BattleMap *map, Mech *mech, LocationSimulation *location) {
9596
float target_speed = location->ds;
9697
if (mech_class(mech) != CLASS_MW && mech_movement_type(mech) != MOVE_VTOL &&
9798
(mech_movement_type(mech) != MOVE_FLY || mech_is_landed(mech)))
98-
target_speed = mech_terrain_speed(mech, target_speed, maximum_speed,
99-
location->t, location->e);
99+
target_speed = mech_terrain_speed(&(MechTerrainSpeedRequest){
100+
.mech = mech,
101+
.current_speed = target_speed,
102+
.maximum_speed = maximum_speed,
103+
.terrain = location->t,
104+
.elevation = location->e,
105+
});
100106
if (heading_changed) {
101107
const int slowdown =
102108
btech_context_movement_slowdown_mode(mech_context(mech));
@@ -135,12 +141,10 @@ int ai_crash(BattleMap *map, Mech *mech, LocationSimulation *location) {
135141
}
136142
}
137143

138-
float x_delta = 0.0F;
139-
float y_delta = 0.0F;
140-
FindComponents(location->s * (float)MOVE_MOD, location->h, &x_delta,
141-
&y_delta);
142-
location->fx += x_delta;
143-
location->fy += y_delta;
144+
MapRealPosition delta = map_vector_components(&(MapPolarVector){
145+
.magnitude = location->s * (float)MOVE_MOD, .bearing = location->h});
146+
location->fx += delta.x;
147+
location->fy += delta.y;
144148
location->lx = location->x;
145149
location->ly = location->y;
146150
RealCoordToMapCoord(&location->x, &location->y, location->fx, location->fy);

src/btech/autopilot/autopilot.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <time.h>
77

88
#include "btech_event.h"
9+
#include "map_coordinates.h"
910
#include "mech_events.h"
1011
#include "mux/server/platform.h"
1112
#include "mux/support/doubly_linked_list.h"
@@ -56,7 +57,7 @@ constexpr int AUTOPILOT_FOLLOW_TICK = 4;
5657
*/
5758

5859
#define AUTOPILOT_STARTUP_TICK \
59-
STARTUP_TIME + AUTOPILOT_NC_DELAY /* Delay for startup */
60+
(STARTUP_TIME + AUTOPILOT_NC_DELAY) /* Delay for startup */
6061

6162
/* Defines for the autogun/autosensor stuff */
6263
constexpr int AUTO_GUN_TICK = 1; /* Every second */
@@ -387,10 +388,15 @@ void auto_leave_event(MuxEvent *muxevent);
387388
void auto_enter_event(MuxEvent *muxevent);
388389
void auto_command_roam(Autopilot *autopilot, Mech *mech);
389390
void auto_astar_roam_event(MuxEvent *muxevent);
390-
void speed_up_if_neccessary(Autopilot *autopilot, Mech *mech, int target_x,
391-
int target_y, int bearing);
392-
int slow_down_if_neccessary(Autopilot *autopilot, Mech *mech, float range,
393-
int bearing, int target_x, int target_y);
391+
typedef struct AutopilotApproachRequest {
392+
Autopilot *autopilot;
393+
Mech *mech;
394+
MapHexPosition target;
395+
int bearing;
396+
float range;
397+
} AutopilotApproachRequest;
398+
void autopilot_speed_up_for_target(const AutopilotApproachRequest *request);
399+
bool autopilot_slow_down_for_target(const AutopilotApproachRequest *request);
394400
void update_wanted_heading(Autopilot *autopilot, Mech *mech, int bearing);
395401

396402
/* From autopilot_ai.c */

0 commit comments

Comments
 (0)