Skip to content

Commit

Permalink
Better Automation
Browse files Browse the repository at this point in the history
GOAP miner role, that can navigate to a market to sell instead of just docking where it's at. Market ranking is a bit wack and not all operations are conveyed to the user but it's nice.
  • Loading branch information
Alkaliii committed Jul 4, 2023
1 parent 91cf155 commit 3d61476
Show file tree
Hide file tree
Showing 39 changed files with 2,028 additions and 480 deletions.
32 changes: 31 additions & 1 deletion AgentDetails.gd
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,14 @@ signal PurchaseShip
signal PurchaseCargo
signal SellCargo
signal JettisonCargo
signal TransferCargo
signal TransferTarget
signal TransferTargetUpdate

signal showFMAPbut

signal updateAgent

signal mapHOME
signal mapSEL(sym)
signal mapGenLine(one,two)
Expand Down Expand Up @@ -106,13 +111,15 @@ func clear():
AgentSymbol = ""
USERTOKEN = ""

func queryUser_Ship(waypoint = null):
func queryUser_Ship(waypoint = null,condition = ""):
var Ships : Array
if waypoint == null:
for s in _FleetData["data"]:
Ships.push_back(s)
else:
for s in _FleetData["data"]:
if s["symbol"] == focusShip and condition == "TRANSFER": continue
if s["cargo"]["units"] == s["cargo"]["capacity"] and condition == "TRANSFER": continue
if s["nav"]["waypointSymbol"] == waypoint and s["nav"]["status"] != "IN_TRANSIT":
Ships.push_back(s)
if Ships.size() == 1:
Expand Down Expand Up @@ -149,6 +156,29 @@ func setInterfaceShip(symbol):
#print(symbol)
emit_signal("interfaceShipSet")

func cleanSurveys():
#Assumptions
#A good price is >20
#More deposits is a good thing

if surveys.empty(): return
for s in surveys:
#Expired
if Time.get_unix_time_from_datetime_string(surveys[s]["expiration"]) < Time.get_unix_time_from_system():
surveys.erase(s)
continue

var score = 0
score += surveys[s]["deposits"].size()

for d in surveys[s]["deposits"]:
score += sellgood[d["symbol"]]["LatestSellPrice"]

match surveys[s]["size"]:
"SMALL": score += 0
"MODERATE": score += 10
"LARGE": score += 20

func acceptContract(CID, node):
var HTTP = HTTPRequest.new()
self.add_child(HTTP)
Expand Down
4 changes: 4 additions & 0 deletions Automation/AutoExtract.gd
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func _ready():
add_state("Yield_Dock") #-> Purge,Visit
add_state("Visit_Market") #-> Purge
add_state("Purge") #-> Orbit
add_state("pause")
add_state("error")

func endFSM():
Expand Down Expand Up @@ -295,6 +296,7 @@ func _enter_state(new_state, old_state):
}

Automation.callQueue.push_back(PURGE_POST_REQUEST_OBj)
yield(self,"cargo_sold")

Leftover = shipData["cargo"]["capacity"] - rmvAMT

Expand Down Expand Up @@ -367,6 +369,7 @@ func _on_MARKETrequest_completed(result, response_code, headers, body):
else:
Agent.emit_signal("visitmarket",cleanbody,shipData["nav"]["waypointSymbol"],shipData["nav"]["systemSymbol"],true)

signal cargo_sold
func _on_SELLrequest_completed(result, response_code, headers, body):
var json = JSON.parse(body.get_string_from_utf8())
var cleanbody = json.result
Expand All @@ -375,4 +378,5 @@ func _on_SELLrequest_completed(result, response_code, headers, body):
pass
else:
shipData["cargo"] = cleanbody["data"]["cargo"]
emit_signal("cargo_sold")
Agent.emit_signal("SellCargo",cleanbody)
2 changes: 2 additions & 0 deletions Automation/AutoExtractRoutine.gd
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ func startRoutine():
yield(get_tree(),"idle_frame")
officer.set_state(officer.STATES["Extract"])
#yield(get_tree().create_timer(0.2),"timeout")

func pauseRoutine(): pass
28 changes: 27 additions & 1 deletion Automation/AutomationManager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ signal PushAPI

signal LISTSHIPS
signal SHIPSTATUSUPDATE
signal SHIPTRANSITFINISHED
signal GETSYSTEM
signal LISTSYSTEMWAYPOINTS
signal EXTRACTRESOURCES
Expand All @@ -70,10 +71,14 @@ func _ready():
Agent.connect("DockFinished",self,"cacheSHIPstatus")
Agent.connect("OrbitFinished",self,"cacheSHIPstatus")
Agent.connect("JettisonCargo",self,"cacheJETTISON")
Agent.connect("TransferCargo",self,"cacheTRANSFER")
Agent.connect("TransferTargetUpdate",self,"cacheCARGO_UPDATE")
Agent.connect("PurchaseCargo",self,"cachePURCHASE")
Agent.connect("SellCargo",self,"cacheSELL")
Agent.connect("visitmarket",self,"cacheMARKET")

API.connect("get_market_complete",self,"cacheMARKET")

_setRate(SelectRateTime)
#activateAu()
# for i in 25:
Expand Down Expand Up @@ -166,24 +171,28 @@ func setRoutine(data):
match data["state"]:
"Stop":
for c in self.get_children():
if c is HTTPRequest: continue
if c.assigned_Group == data["group"]:
c.endRoutine()
print(c.name," was ended")
return
"Pause":
for c in self.get_children():
if c is HTTPRequest: continue
if c.assigned_Group == data["group"]:
c.pauseRoutine()
print(c.name," was paused")
return
"Restart":
for c in self.get_children():
if c is HTTPRequest: continue
if c.assigned_Group == data["group"]:
c.restartRoutine()
print(c.name," was restarted")
return

for c in self.get_children():
if c is HTTPRequest: continue
if c.assigned_Group == data["group"]:
c.resumeRoutine()
print(c.name," was resumed")
Expand Down Expand Up @@ -304,6 +313,7 @@ func _on_request_completed(result, response_code, headers, body):
var cleanbody = json.result
if cleanbody is Dictionary and cleanbody.has("error"):
Agent.dispError(cleanbody)
OS.request_attention()
if cleanbody["error"]["code"] in [429,409]:
for req in progressQueue:
callQueue.push_back(progressQueue[req])
Expand Down Expand Up @@ -337,6 +347,13 @@ func cacheEXTRACT(data):
func cacheJETTISON(data):
_FleetData[data["meta"]]["cargo"] = data["data"]["cargo"]

func cacheTRANSFER(data):
_FleetData[data["meta"]]["cargo"] = data["data"]["cargo"]
#print(data)

func cacheCARGO_UPDATE(data):
_FleetData[data["meta"]]["cargo"] = data["data"]

func cachePURCHASE(data):
_FleetData[data["data"]["transaction"]["shipSymbol"]]["cargo"] = data["data"]["cargo"]

Expand All @@ -351,13 +368,19 @@ func cacheSELL(data):
var TotalRevenue = Agent.sellgood[data["data"]["transaction"]["tradeSymbol"]]["TotalRevenue"]
var NewTotalRevenue = TotalRevenue[TotalRevenue.size()-1].values()[0] + data["data"]["transaction"]["totalPrice"]
TotalRevenue.push_back({str(Time.get_unix_time_from_system()):NewTotalRevenue})

#Use sell price to set focus, note which market had the good price for script to use when devising flight plan
var SellPrice = data["data"]["transaction"]["pricePerUnit"]
Agent.sellgood[data["data"]["transaction"]["tradeSymbol"]]["LatestSellPrice"] = SellPrice
else:
var FirstTotalSold = {str(Time.get_unix_time_from_system()):data["data"]["transaction"]["units"]}
var FirstTotalRevenue = {str(Time.get_unix_time_from_system()):data["data"]["transaction"]["totalPrice"]}
var SellPrice = data["data"]["transaction"]["pricePerUnit"]
Agent.sellgood[data["data"]["transaction"]["tradeSymbol"]] = {
"symbol": data["data"]["transaction"]["tradeSymbol"],
"TotalSold": [FirstTotalSold],
"TotalRevenue": [FirstTotalRevenue]
"TotalRevenue": [FirstTotalRevenue],
"LatestSellPrice": SellPrice
}

if Agent.sellship.has(data["data"]["transaction"]["shipSymbol"]):
Expand All @@ -380,7 +403,10 @@ func cacheSHIPstatus(data):
yield(get_tree(),"idle_frame")
if expire < Time.get_unix_time_from_system():
break

_FleetData[data["meta"]]["nav"]["status"] = "IN_ORBIT"
emit_signal("SHIPTRANSITFINISHED",_FleetData[data["meta"]]["nav"])


func cacheMARKET(data,ws = null,ss = null,_4 = null):
_MarketData[data["data"]["symbol"]] = data["data"]
8 changes: 4 additions & 4 deletions Automation/GOAP/Actions/Devise_Extract_Site_Flight_Plan.gd
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ func compute(relevant):

var max_reach
var refuel = false
for m in Automation._MarketData: if m["symbol"] == location: #determine if location is a refuel site
for tg in m["exchange"]:
for m in Automation._MarketData: if m == location: #determine if location is a refuel site
for tg in Automation._MarketData[m]["exchange"]:
if tg["symbol"] == "FUEL":
refuel = true
break
if !refuel: for tg in m["exports"]:
if !refuel: for tg in Automation._MarketData[m]["exports"]:
if tg["symbol"] == "FUEL":
refuel = true
break
if !refuel: for tg in m["imports"]:
if !refuel: for tg in Automation._MarketData[m]["imports"]:
if tg["symbol"] == "FUEL":
refuel = true
break
Expand Down
Loading

0 comments on commit 3d61476

Please sign in to comment.