Move agent logic - updates agent state and related entities
| 288 | |
| 289 | // Move agent logic - updates agent state and related entities |
| 290 | void move_agent(ReducerContext& ctx, GameEnemyAiAgentState& agent, |
| 291 | const SmallHexTile& agent_coord, uint64_t current_time_ms) { |
| 292 | uint64_t entity_id = agent.entity_id; |
| 293 | |
| 294 | // Update enemy state |
| 295 | auto enemy_opt = ctx.db[game_enemy_state_entity_id].find(entity_id); |
| 296 | if (!enemy_opt) { |
| 297 | LOG_PANIC("GameEnemyState Entity ID not found"); |
| 298 | return; |
| 299 | } |
| 300 | auto enemy = *enemy_opt; |
| 301 | auto _updated = ctx.db[game_enemy_state_entity_id].update(enemy); |
| 302 | |
| 303 | // Update agent timestamp |
| 304 | agent.next_action_timestamp = current_time_ms + 2000; |
| 305 | |
| 306 | // Track movement timestamps |
| 307 | agent.last_move_timestamps.push_back(current_time_ms); |
| 308 | if (agent.last_move_timestamps.size() > MAX_MOVE_TIMESTAMPS) { |
| 309 | agent.last_move_timestamps.erase(agent.last_move_timestamps.begin()); |
| 310 | } |
| 311 | |
| 312 | // Update targetable state |
| 313 | auto targetable_opt = ctx.db[game_targetable_state_entity_id].find(entity_id); |
| 314 | if (!targetable_opt) { |
| 315 | LOG_PANIC("GameTargetableState Entity ID not found"); |
| 316 | return; |
| 317 | } |
| 318 | auto targetable = *targetable_opt; |
| 319 | int64_t new_hash = static_cast<int64_t>(calculate_hash(targetable.quad)); |
| 320 | targetable.quad = new_hash; |
| 321 | _updated = ctx.db[game_targetable_state_entity_id].update(targetable); |
| 322 | |
| 323 | // Update live targetable state if exists |
| 324 | auto live_targetable_opt = ctx.db[game_live_targetable_state_entity_id].find(entity_id); |
| 325 | if (live_targetable_opt) { |
| 326 | GameLiveTargetableState live_targetable = {entity_id, new_hash}; |
| 327 | ctx.db[game_live_targetable_state_entity_id].update(live_targetable); |
| 328 | } |
| 329 | |
| 330 | // Update mobile entity state |
| 331 | auto mobile_entity_opt = ctx.db[game_mobile_entity_state_entity_id].find(entity_id); |
| 332 | if (!mobile_entity_opt) { |
| 333 | LOG_PANIC("GameMobileEntityState Entity ID not found"); |
| 334 | return; |
| 335 | } |
| 336 | auto mobile_entity = *mobile_entity_opt; |
| 337 | mobile_entity.location_x += 1; |
| 338 | mobile_entity.location_y += 1; |
| 339 | mobile_entity.timestamp = agent.next_action_timestamp; |
| 340 | |
| 341 | // Update agent state and mobile entity |
| 342 | _updated = ctx.db[game_enemy_ai_agent_state_entity_id].update(agent); |
| 343 | _updated = ctx.db[game_mobile_entity_state_entity_id].update(mobile_entity); |
| 344 | } |
| 345 | |
| 346 | // Main agent loop processing |
| 347 | void agent_loop(ReducerContext& ctx, GameEnemyAiAgentState& agent, |
no test coverage detected
searching dependent graphs…