# =============================================================================
# FULL COMBAT SYSTEM — Demonstrates HERB's Temporal Facts with Provenance
# =============================================================================
#
# This shows the complete chain: attack -> damage calc -> apply -> death -> loot
# Every derived fact knows WHEN it happened and WHY.
#
# Key features demonstrated:
# 1. Arithmetic in templates: (- ?hp ?damage)
# 2. RETRACT to consume events: pending_damage -> applied
# 3. Provenance: explain why anything is true
# 4. Temporal queries: what was HP at tick N?

# =============================================================================
# WORLD SETUP
# =============================================================================

# --- The Hero ---
FACT hero is_a combatant
FACT hero is_a player
FACT hero hp 100
FACT hero max_hp 100
FACT hero attack 30
FACT hero defense 15
FACT hero gold 50

# --- A Goblin ---
FACT goblin is_a combatant
FACT goblin is_a monster
FACT goblin hp 25
FACT goblin max_hp 25
FACT goblin attack 8
FACT goblin defense 3
FACT goblin hostile true
FACT goblin loot_gold 15

# --- Locations ---
FACT hero location forest
FACT goblin location forest
FACT forest is_a location

# =============================================================================
# COMBAT RULES
# =============================================================================

# R1: Combat proximity - combatants in same location can fight
RULE combat_proximity
  WHEN ?a is_a combatant
  AND ?b is_a combatant
  AND ?a location ?loc
  AND ?b location ?loc
  THEN ?a can_target ?b

# R2: Hostile monsters auto-attack players they can target
RULE monster_attacks
  WHEN ?m is_a monster
  AND ?m hostile true
  AND ?p is_a player
  AND ?m can_target ?p
  THEN ?m attacks ?p

# R3: Players counter-attack monsters that attack them
RULE player_counters
  WHEN ?m attacks ?p
  AND ?p is_a player
  THEN ?p attacks ?m
