townforge/ragnar's raids/ragnar's raids - raiding.tf
2022-08-04 15:57:39 +00:00

89 lines
3.4 KiB
HCL

script {
name "Ragnar's raids - Raiding"
description "Automated raid resolution"
owner 0
precondition player id == 2 # game only
state "init" {
init {
if (local "init_done" == 0)
{
set local "flotilla_size" min(global "ragnar_raids_wood" / 200, global "ragnar_raids_gold" / 20000000)
set local "plunder_capacity" local "flotilla_size" / 2
set local "raiding_strength" min(min(global "ragnar_raids_labour" / 25, global "ragnar_raids_gold" / 2000000), local "flotilla_size" * 30 / 2)
set local "food_consumption" local "raiding_strength" * 75 / 10
set global "ragnar_raids_plunder" 0
set local "num_turns" 0
set local "food_left" global "ragnar_raids_food"
set local "init_done" 1
log "flotilla_size: %u" local "flotilla_size"
log "plunder_capacity: %u" local "plunder_capacity"
log "raiding_strength: %u" local "raiding_strength"
log "food_consumption: %u" local "food_consumption"
}
set local "num_turns" local "num_turns" + 1
set local "food_needed" local "food_consumption" - local "food_consumption" / 10 + local "food_consumption" * (random 200) / 1000
if (blockchain height >= global "ragnar_raids_set_sail_height" and local "set_sail_message_sent" == 0) {
storyline event "The raiding fleet has set sail"
set local "set_sail_message_sent" 1
}
set local "R1" random 100
set local "R2" random 1000
log "food_left: %u" local "food_left"
log "food_needed: %u" local "food_needed"
}
choice {
# wait till our start height is reached
enabled blockchain height < global "ragnar_raids_set_sail_height"
next state "init"
}
choice {
enabled local "num_turns" > 12
actions {
storyline event "The raid has ended, and the flotilla is back to port, ready to divide the plunder"
set global "ragnar_raids_plunder_ready" 1
}
}
choice {
enabled local "food_left" < local "food_needed"
actions {
storyline event "The flotilla ran out of food and is back to port, ready to divide the plunder"
set global "ragnar_raids_plunder_ready" 1
}
}
choice {
enabled global "ragnar_raids_plunder" >= local "plunder_capacity"
actions {
storyline event "The flotilla has ammassed enough plunder to fill the ships and is now back to port, ready to divide the plunder"
set global "ragnar_raids_plunder_ready" 1
}
}
choice {
enabled local "R1" > 20
actions {
set local "food_left" local "food_left" - local "food_needed"
storyline event "The raiding party sails, searching for a suitable place to raid"
}
next state "init"
}
choice {
enabled local "R2" < 50000 / local "raiding_strength"
actions {
set local "food_left" local "food_left" - local "food_needed"
storyline event "The raiding party attacked a settlement but was pushed back by the defenders"
}
next state "init"
}
choice {
actions {
set local "food_left" local "food_left" - local "food_needed"
set local "gold_plundered" min(max(1.0, 15 * sqrt(random 1000000 * local "raiding_strength") / 10000), local "plunder_capacity" - global "ragnar_raids_plunder")
storyline event "The raiding party attacked a settlement and plundered %G gold!" local "gold_plundered"
}
next state "init"
}
}
}