add examples

This commit is contained in:
Joeri Exelmans 2024-11-13 10:07:16 +01:00
parent 8504ba52f6
commit 42757ddc4f
35 changed files with 1104 additions and 609 deletions

View file

@ -0,0 +1,4 @@
clock:RAM_Clock {
RAM_time = `True`;
}

View file

@ -0,0 +1,27 @@
clock:RAM_Clock {
RAM_time = `get_value(this) + 1`;
}
# Advance time has a bunch of side-effects that we cannot easily model using NAC/LHS/RHS-kind of rules,
# so we just do it in code:
:GlobalCondition {
condition = ```
for _, attacking_link in get_all_instances("attacking"):
man_state = get_target(attacking_link)
animal_state = get_source(attacking_link)
if get_type_name(animal_state) == "BearState":
# Bear hunger decreases
set_slot_value(animal_state, "hunger", max(get_slot_value(animal_state, "hunger") - 50, 0))
set_slot_value(man_state, "dead", True)
delete(attacking_link)
# Bear hunger increases
for _, bear_state in get_all_instances("BearState"):
if get_slot_value(bear_state, "dead"):
continue # bear already dead
old_hunger = get_slot_value(bear_state, "hunger")
new_hunger = min(old_hunger + 10, 100)
set_slot_value(bear_state, "hunger", new_hunger)
```;
}

View file

@ -0,0 +1,18 @@
# Some man is afraid of some animal:
man:RAM_Man
animal:RAM_Animal
manAfraidOfAnimal:RAM_afraidOf (man -> animal)
# Both man and animal have an associated state:
manState:RAM_ManState
man2State:RAM_of (manState -> man)
animalState:RAM_AnimalState
animal2State:RAM_of (animalState -> animal)

View file

@ -0,0 +1,7 @@
# Cannot attack if already attacking
manState:RAM_ManState
animalState:RAM_AnimalState
:RAM_attacking(animalState -> manState)

View file

@ -0,0 +1,7 @@
# Bear won't attack unless hungry
animalState:RAM_AnimalState {
condition = ```
get_type_name(this) == "BearState" and get_slot_value(this, "hunger") < 50
```;
}

View file

@ -0,0 +1,5 @@
# If dead, cannot be attacked
manState:RAM_ManState {
RAM_dead = `get_value(this)`;
}

View file

@ -0,0 +1,5 @@
# If dead, cannot attack
animalState:RAM_AnimalState {
RAM_dead = `get_value(this)`;
}

View file

@ -0,0 +1,7 @@
# Not already attacking someone else:
animalState:RAM_AnimalState
other:RAM_ManState
:RAM_attacking(animalState -> other)

View file

@ -0,0 +1,7 @@
# Not already being attacked by someone else:
manState:RAM_ManState
other:RAM_AnimalState
:RAM_attacking(other -> manState)

View file

@ -0,0 +1,28 @@
# Our entire LHS (don't delete anything)
# Some man is afraid of some animal:
man:RAM_Man
animal:RAM_Animal
manAfraidOfAnimal:RAM_afraidOf (man -> animal)
# Both man and animal have an associated state:
manState:RAM_ManState
man2State:RAM_of (manState -> man)
animalState:RAM_AnimalState
animal2State:RAM_of (animalState -> animal)
# Animal attacks man:
:RAM_attacking(animalState -> manState) {
RAM_starttime = `get_slot_value(get_all_instances("Clock")[0][1], "time")`;
}

View file

@ -0,0 +1,8 @@
bearState:RAM_BearState {
RAM_hunger = ```
get_value(this) == 100
```;
RAM_dead = ```
not get_value(this)
```;
}

View file

@ -0,0 +1,4 @@
bearState:RAM_BearState {
RAM_hunger = `get_value(this)`; # unchanged
RAM_dead = `True`;
}