Skip to content

Commit 579a01f

Browse files
Merge pull request #39 from meltingscales/feature-combat
Feature: add combat
2 parents 1a99c71 + 7e0ce52 commit 579a01f

File tree

88 files changed

+10243
-2537
lines changed

Some content is hidden

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

88 files changed

+10243
-2537
lines changed
Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
1+
# AI Instructions
2+
13
You are allowed to run `just build` and `just install`, and also `just run-*`. This game was going to use a GUI (bevy), but I decided that `ratatui` would be faster, so we're back to using a TUI.
24

5+
If you're running NixOS, make sure to run `nix-shell` to get the right environment.
6+
7+
`./docs/*.md` contains lots of useful documentation.
8+
39
You should use `rustup` to run `cargo` and other tools.
410

511
Please avoid running `cargo clean`. It takes a long time to rebuild rust modules.
612

7-
Keep small copyrights inside of the main game code files. Make sure they exist if they aren't declared.
13+
Also never run `just client` or any other TUI because you might be in a terminal that cannot display properly as you're an AI agent. Instead, ask me to run `just client` or use unit testing to test code.
14+
15+
## Testing
16+
17+
Run tests with `make test` to validate game systems. Write simple unit tests for:
18+
- Combat mechanics (damage, death, action queues)
19+
- Game logic (movement, energy, cooldowns)
20+
- Edge cases and bug fixes
21+
22+
Tests help ensure systems work correctly and prevent regressions during development.
823

9-
Guiding principles:
24+
## Guiding principles
1025

1126
- All randomly-generated choices, actions, damage, loot, worldgen, etc - should be fully deterministic and based on world seed and world tick. This means that this game should be fully TAS-able for any specific initial seed (and version of game code). Always use the seed and any permutation (when appropriate) of XYZ coordinate, biome, or other seeded randomness to generate anything "random".
1227

@@ -16,9 +31,9 @@ Guiding principles:
1631

1732
- This game renders using ASCII text.
1833

19-
- TODO.md contains a big, unedited list of my long-term goals with this game. By no means do we need to implement all of them. I will likely cut or edit parts of the TODO. I just want to focus on the section called "MVP for steam release (2026)".
34+
- docs/TODO.md contains a big, unedited list of my long-term goals with this game. By no means do we need to implement all of them. I will likely cut or edit parts of the TODO. I just want to focus on the section called "MVP for steam release (2026)".
2035

21-
- We're currently in the process of migrating from Python to Rust. Please see the migration plan for more information, called "migration-plan.md" and "TODO-RUST-MIGRATION.md".
36+
- We're currently in the process of migrating from Python to Rust. Please see the migration plan for more information, called "docs/migration-plan.md" and "docs/TODO-RUST-MIGRATION.md".
2237

2338
Periodic tasks:
2439

.ai/prompt_3d_voxel_editors.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
> What would be a good choice for making custom structures or maps? I know that @crates/client/assets/structures/small_temple.lrstructure/shape_layers.txt is one way to store it but...it's not really easy to visualize. Are there any low-res voxel 3D editors that I could then make a custom exporter for? I want to make the main questline's factory that's 10 miles away [- the first quest is to travel 10 miles to the robotics factory that made you to replace your damaged fusion core and fix your limbs. you remember the location. TODO add a maps and waypoint system.] and I want to design it by hand, but not in our shape_layers.txt format because it's pretty limited.
2+
3+
I'd like to avoid MagicaVoxel because i primarily use linux to develop.
4+
5+
reply from ai:
6+
7+
Best Options for Linux:
8+
9+
1. Goxel - Open source, specifically designed for voxel editing, lightweight and perfect for game assets
10+
2. VoxEdit (The Sandbox) - Free voxel editor with good export options
11+
3. Qubicle - Professional voxel editor with Linux support (paid)
12+
4. Blender with voxel addons - Free, powerful, and you could use addons like "Voxel Tools" or "Extra Objects"
13+
14+
Recommended Approach:
15+
Goxel would be my top recommendation - it's:
16+
- Native Linux support
17+
- Lightweight and fast
18+
- Exports to various formats (PLY, OBJ, etc.)
19+
- Simple enough for game structures but powerful enough for detail
20+
21+
Custom Export Strategy:
22+
You could create a simple converter that:
23+
1. Exports from Goxel as PLY/OBJ
24+
2. Reads the mesh data
25+
3. Converts to your shape_layers.txt format or a new binary format
26+
4. Handles multiple layers/materials if needed

.ai/prompt_class_analysis.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Run `just analyze-modules` and `just complexity` and give me a summary of what I should do to improve the codebase, and any good patterns you see as well. You can also run `just analyze-deps` to see what dependencies we're using.

.ai/prompt_refactor_meta.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
I'd like you to give me prompt suggestions to examine how clean/messy my state is. Things like unnecessary complexity or state tangledness. I'll be feeding these prompts to Claude CLI to help me determine how to refactor my code.
2+
3+
oh, and run `make tokei` to see a summary of code files.

.ai/prompt_split_code_files.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Modularize code
2+
3+
I'd like you to run `make tokei` and read code files, and offer suggestions on how to make my code more modular so that AI can more easily read it.

.ai/prompt_testing.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# testing
2+
3+
I'd like you to run `make test` and offer advice about code coverage and my code's structure so that we can more easily test our code.

.ai/prompts_state_mgmt.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Examine how game state flows through the system - identify places where state is duplicated or inconsistently managed.
2+
3+
Find components that have too many responsibilities by analyzing the components.rs and systems.rs files.
4+
5+
Look for global state access patterns and suggest more localized state management.

.ai/todo_combat_code_issues.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Combat Code Issues - Priority List
2+
3+
Generated: 2025-01-27
4+
5+
## 🎯 **Recently Fixed Issues**
6+
- ✅ Move queuing after killing all enemies (combat state validation)
7+
- ✅ Duplicate queue cleanup logic (centralized cleanup function)
8+
- ✅ Queue cleanup not removing actions targeting dead entities
9+
-**Race Condition in Action Queue Processing** - Refactored to two-phase processing
10+
-**No Validation of Action Targets During Execution** - Added target validation checks
11+
12+
## 🔍 **Outstanding Issues by Severity**
13+
14+
### 🚨 **HIGH SEVERITY**
15+
16+
*All high severity issues have been resolved! 🎉*
17+
18+
### 🟡 **MEDIUM SEVERITY**
19+
20+
#### 3. **Inconsistent Combat State Management***Medium Effort***RESOLVED**
21+
- **Location**: Multiple files - combat state checked in various places
22+
- **Issue**: Combat state is checked/set in multiple places with different conditions
23+
- **Impact**: Possible states where combat UI shows but combat logic isn't active
24+
- **Fix**: ✅ Created centralized `CombatStateManager` system in `/home/melty/Git/LithicRivers/crates/core/src/combat_state_manager.rs`
25+
- **Code Changes**: ✅ Centralized all combat state transitions, replaced old `combat_trigger_system` usage in system_scheduler.rs
26+
27+
#### 4. **Performance: O(n²) Queue Cleanup***Medium Effort***RESOLVED**
28+
- **Location**: `cleanup_actions_targeting_dead_entity()` in `/home/melty/Git/LithicRivers/crates/core/src/systems.rs:1085`
29+
- **Issue**: Every entity death iterates through ALL entities with queues
30+
- **Impact**: Performance degrades with many entities in large battles
31+
- **Fix**: ✅ Implemented `TargetTracker` resource with reverse lookup `HashMap<Entity, HashSet<Entity>>`
32+
- **Code Changes**: ✅ Created `/home/melty/Git/LithicRivers/crates/core/src/target_tracker.rs`, optimized cleanup function reduces from O(n²) to O(1) + O(k) where k = entities targeting dead one
33+
34+
#### 5. **Memory Leak: Dead Entities with Components***Low Effort*
35+
- **Location**: Entity cleanup throughout codebase
36+
- **Issue**: Dead entities keep their ActionQueue and other components until manually cleaned
37+
- **Impact**: Memory usage grows during long combat sessions
38+
- **Fix**: Add periodic cleanup system or immediate component removal on death
39+
- **Code Changes**: Extend cleanup functions to remove all unnecessary components
40+
41+
#### 6. **No Action Priority System***High Effort*
42+
- **Location**: `ActionQueue` system in `/home/melty/Git/LithicRivers/crates/core/src/moves.rs:278`
43+
- **Issue**: All actions execute in timing order only, no tactical priority
44+
- **Impact**: Unrealistic combat where healing can't interrupt attacks
45+
- **Fix**: Add priority levels to actions and priority-based queue sorting
46+
- **Code Changes**: Major refactor of action queue to support priority levels
47+
48+
### 🟢 **LOW SEVERITY**
49+
50+
#### 7. **UI Shows Entity IDs Instead of Names***Low Effort*
51+
- **Location**: Combat UI in `/home/melty/Git/LithicRivers/crates/client/src/ui/panels/combat.rs:222`
52+
- **Issue**: Target display shows "Enemy 42" instead of "Goblin" or similar
53+
- **Impact**: Poor user experience, harder to track specific enemies
54+
- **Fix**: Add name component lookup in UI target display logic
55+
- **Code Changes**: Add Name component and lookup in UI rendering
56+
57+
#### 8. **No Action Animation/Feedback Delay***Medium Effort*
58+
- **Location**: Action execution system
59+
- **Issue**: Actions complete instantly with no visual feedback period
60+
- **Impact**: Combat feels disconnected, hard to follow action flow
61+
- **Fix**: Add animation/feedback phase to action execution
62+
- **Code Changes**: Add animation states and timing to action system
63+
64+
#### 9. **Hard-coded Move Validation***Medium Effort*
65+
- **Location**: Input handler `/home/melty/Git/LithicRivers/crates/client/src/app/input_handler.rs:677`
66+
- **Issue**: Move #3 is hard-coded as "Escape" in input handler
67+
- **Impact**: Fragile code, breaks if move list changes
68+
- **Fix**: Add move metadata for target requirements
69+
- **Code Changes**: Add `requires_target` field to Move struct
70+
71+
#### 10. **Limited Error Recovery***Low Effort*
72+
- **Location**: Various action execution paths
73+
- **Issue**: Failed actions don't provide recovery mechanisms
74+
- **Impact**: Players can get stuck in invalid states
75+
- **Fix**: Add action validation and error state recovery
76+
- **Code Changes**: Add validation checks and fallback behaviors
77+
78+
## 📊 **Summary Statistics**
79+
80+
### By Severity:
81+
- **High**: 0 issues ✅ (All resolved!)
82+
- **Medium**: 2 issues (performance/UX problems) - 2 resolved ✅
83+
- **Low**: 4 issues (polish/maintainability)
84+
85+
### By Effort:
86+
- **Low Effort**: 4 issues (quick fixes)
87+
- **Medium Effort**: 5 issues (moderate refactoring)
88+
- **High Effort**: 1 issue (major feature addition)
89+
90+
## 🎯 **Recommended Fix Order**
91+
92+
### Phase 1 - Critical Fixes (High Impact, Lower Effort)
93+
1. **Action target validation** (High Severity, Low Effort) - Prevents crashes
94+
2. **Memory leak cleanup** (Medium Severity, Low Effort) - Performance improvement
95+
3. **UI entity names** (Low Severity, Low Effort) - Quick UX win
96+
97+
### Phase 2 - Performance & Stability (Medium Effort)
98+
4. **Race condition fix** (High Severity, Medium Effort) - System stability
99+
5. **Queue cleanup performance** (Medium Severity, Medium Effort) - Scalability
100+
6. **Combat state centralization** (Medium Severity, Medium Effort) - Maintainability
101+
102+
### Phase 3 - Polish & Features (Higher Effort)
103+
7. **Hard-coded move validation** (Low Severity, Medium Effort) - Code quality
104+
8. **Animation system** (Low Severity, Medium Effort) - UX improvement
105+
9. **Error recovery** (Low Severity, Low Effort) - Robustness
106+
10. **Priority system** (Medium Severity, High Effort) - Major feature
107+
108+
## 🔧 **Technical Notes**
109+
110+
- All high severity issues should be addressed before major feature additions
111+
- The race condition fix (#1) is the most critical as it affects system stability
112+
- Performance issues (#4) will become more apparent with larger battles
113+
- Priority system (#6) would be a good candidate for a major refactor milestone

.ai/todo_world_sim_tests.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
I'd like you to add a unit test that simulates a game world running to catch this in the future - combat working, debugInstantKill actually killing, combat joining working, etc.
2+
3+
also, how hard would it be to make unit tests that simulate the world BTW? Just tell me.
4+
we can do things like, walking 10,000 steps, death due to waiting in combat, stress testing things, etc.

.claude/settings.local.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"permissions": {
3+
"allow": [
4+
"Bash(make:*)",
5+
"Bash(grep:*)",
6+
"Bash(mkdir:*)",
7+
"Bash(sed:*)",
8+
"Bash(cargo check:*)",
9+
"Bash(find:*)",
10+
"Bash(rustup run nightly cargo clippy:*)",
11+
"Bash(just clippy:*)",
12+
"Bash(rustup run stable cargo check)",
13+
"Bash(just build)",
14+
"Bash(rustc:*)",
15+
"Bash(rustup run nightly cargo build:*)",
16+
"Bash(/dev/null)",
17+
"Bash(cargo:*)",
18+
"Bash(timeout 2s cargo run --bin lithicrivers-client)",
19+
"Bash(timeout 3s cargo run --bin lithicrivers-client)",
20+
"Bash(timeout 10s make build)",
21+
"Bash(timeout 3s make build)",
22+
"Bash(just test:*)",
23+
"Bash(RUSTFLAGS='-Z unstable-options' RUSTDOCFLAGS='-Z unstable-options' RUSTC_BOOTSTRAP=1 rustup run nightly cargo test -p lithicrivers-core --lib systems::tests::test_combat_system_enemy_death)",
24+
"Bash(timeout 10s cargo run --bin lithicrivers-client)",
25+
"Bash(timeout:*)",
26+
"Bash(cat:*)",
27+
"Bash(rustup:*)",
28+
"Bash(RUSTFLAGS=* rustup:*)",
29+
"Bash(RUST_BACKTRACE=* RUSTFLAGS=* rustup:*)"
30+
],
31+
"deny": [],
32+
"ask": []
33+
}
34+
}

0 commit comments

Comments
 (0)