# HERB Negation Demo
# Demonstrates not-exists for absence checks
#
# Scenario: Tax exemptions in a medieval jurisdiction
# - Shops in a jurisdiction are taxed unless they have an exemption
# - Players allied with a faction are not attacked by that faction's guards
# - NPCs without quests show default behavior

# === FACTS ===

# Players and locations
FACT alice is_a player
FACT bob is_a player
FACT charlie is_a player
FACT alice location market
FACT bob location market
FACT charlie location castle

# Jurisdictions and tax rates
FACT market in_jurisdiction citadel
FACT castle in_jurisdiction citadel
FACT citadel tax_rate 15

# Some players have tax exemptions
FACT alice exemption citadel
# bob has no exemption - will be taxed
# charlie has no exemption but is in castle which has different rules

# Factions and guards
FACT guard_1 is_a guard
FACT guard_1 faction royal
FACT guard_1 location market
FACT guard_2 is_a guard
FACT guard_2 faction royal
FACT guard_2 location castle

# Player alliances
FACT alice allied_with royal
# bob is not allied - guards will be hostile
FACT charlie allied_with royal

# NPCs and quests
FACT merchant is_a npc
FACT merchant location market
# merchant has no quest - will have idle behavior

FACT questgiver is_a npc
FACT questgiver location castle
FACT questgiver has_quest adventure

# === RULES ===

# Rule: Players in jurisdiction without exemption must pay tax
RULE apply_tax
  WHEN ?p is_a player
  AND ?p location ?loc
  AND ?loc in_jurisdiction ?j
  AND ?j tax_rate ?rate
  IF (not-exists ?p exemption ?j)
  THEN ?p owes_tax ?rate

# Rule: Guards are hostile to non-allied players in same location
RULE guard_hostile
  WHEN ?g is_a guard
  AND ?g faction ?f
  AND ?p is_a player
  AND ?g location ?loc
  AND ?p location ?loc
  IF (not-exists ?p allied_with ?f)
  THEN ?g hostile_to ?p

# Rule: NPCs without quests have idle behavior
RULE default_idle
  WHEN ?n is_a npc
  IF (not-exists ?n has_quest ?any)
  THEN ?n behavior idle

# Rule: NPCs with quests have quest_ready behavior
RULE quest_ready
  WHEN ?n is_a npc
  AND ?n has_quest ?q
  THEN ?n behavior quest_ready
