102 lines
No EOL
2.3 KiB
Text
102 lines
No EOL
2.3 KiB
Text
import "math/observable" for Observable
|
|
import "luxe: world" for Entity, Values, Tags
|
|
import "globals" for Globals
|
|
import "blocks/resources" for Resources
|
|
import "math/stringUtil" for StringUtil
|
|
import "blocks/human/human" for Human
|
|
|
|
class Adventures{
|
|
planning{_planning}
|
|
max_distance{_max_distance}
|
|
|
|
construct new(){
|
|
_planning = Observable.new()
|
|
_in_progress = []
|
|
_archive = []
|
|
_max_distance = 10
|
|
_game = Globals["Game"]
|
|
}
|
|
|
|
plan_new(){
|
|
System.print("Start planning new Adventure")
|
|
var adventure = Adventure.new()
|
|
adventure.distance = 2
|
|
_planning.value = adventure
|
|
return adventure
|
|
}
|
|
|
|
dispatch(){
|
|
var adventure = _planning.value
|
|
if(!adventure){
|
|
System.print("Tried to dispatch adventure, but none is planned")
|
|
return
|
|
}
|
|
System.print("Dispatching adventure \"%(adventure)\"")
|
|
|
|
adventure.setup()
|
|
adventure.adventurers.each{|human|
|
|
Human.set_active(human, false)
|
|
}
|
|
adventure.resources.list().each{|resource|
|
|
_game.resources.remove(resource["base_name"], resource["amount"])
|
|
}
|
|
_in_progress.add(adventure)
|
|
_planning.value = null
|
|
}
|
|
|
|
tick(){
|
|
//check some stuff that needs to be checked from time to time
|
|
//once per second/minute/whatever should be enough
|
|
}
|
|
|
|
new_or_current(){
|
|
if(_planning.value) return _planning.value
|
|
return plan_new()
|
|
}
|
|
|
|
discard(){
|
|
_planning.value = null
|
|
}
|
|
|
|
set_max_distance(dist){
|
|
_max_distance = dist
|
|
planning.emit()
|
|
}
|
|
}
|
|
|
|
class Adventure{
|
|
adventurers{_adventurers}
|
|
resources{_resources}
|
|
data{_data}
|
|
direction{_direction}
|
|
direction=(dir){_direction = dir}
|
|
distance{_distance}
|
|
distance=(dist){_distance = dist}
|
|
|
|
toString{
|
|
return "%(adventurers.map{|id| Human.get_name(id)}.toList)"+
|
|
" travelling %(distance)km towards %(StringUtil.direction(direction))"+
|
|
" with %(resources.list().map{|resource| "%(resource["amount"]) %(resource["name"])"}.toList)"
|
|
}
|
|
|
|
construct new(){
|
|
_adventurers = []
|
|
_resources = Resources.new()
|
|
_data = {}
|
|
|
|
_direction = 0
|
|
_distance = 0
|
|
}
|
|
|
|
setup(){
|
|
|
|
}
|
|
|
|
add_adventurer(adventurer){
|
|
_adventurers.add(adventurer)
|
|
}
|
|
|
|
add_resource(resource){
|
|
_resources.add(resource)
|
|
}
|
|
} |