Fixed Trade-Missions

Dixi

Active Member
I always wanted my bot to do Courier and Trade Missions.
Courier-Missions were running smoothly (after fixing the switch-Agent part) but the Trade-Missions were kinda bugged.
I also wanted to look for my assets first before buying the required Ore.

Right now, almost all of my files are Locally Modified, so I will try to reconstruct what I did. I can upload my Files too, but right now they are full of Debug-Messages and I am too lousy to delete them.

1.) obj_Agents.iss
The first problem was, that the function MissionDetails() didn't get the amount of the required item right. That was quite tricky.
It turned out, that the bot tried to read the Mission-Details before they were opened. So I changed this part:

Code:
variable string details
variable int left = 0
variable int right = 0

if !${EVEWindow[ByCaption, "Mission journal - ${This.ActiveAgent}"](exists)}
{
to this:

Code:
variable string details
variable int left = 0
variable int right = 0
		wait 50

if !${EVEWindow[ByCaption, "Mission journal - ${This.ActiveAgent}"](exists)}
{
some lines below I realized that the bot couldn't handle the string to float (? or int?) typecast because of the "," and "." Problem.
so here is the fix for that problem:
change
Code:
				left:Set[${Math.Calc[${right}-16+${left}+1]}]
right:Set[${Math.Calc[${right}-${left}]}]
;UI:UpdateConsole["obj_Agents: DEBUG: left = ${left}"]
;UI:UpdateConsole["obj_Agents: DEBUG: right = ${right}"]
;UI:UpdateConsole["obj_Agents: DEBUG: string = ${details.Escape.Mid[${left},${right}]}"]
volume:Set[${details.Escape.Mid[${left},${right}]}]
UI:UpdateConsole["obj_Agents: DEBUG: volume = ${volume}"]
to

Code:
				left:Set[${Math.Calc[${right}-16+${left}+1]}]
right:Set[${Math.Calc[${right}-${left}]}]
;UI:UpdateConsole["obj_Agents: DEBUG: left = ${left}"]
;UI:UpdateConsole["obj_Agents: DEBUG: right = ${right}"]
;UI:UpdateConsole["obj_Agents: DEBUG: string = ${details.Escape.Mid[${left},${right}]}"]
volume:Set[${details.Escape.Mid[${left},${right}].Replace[",","."]}]
UI:UpdateConsole["obj_Agents: DEBUG: volume = ${volume}"]

2.) obj-Cargo.iss
insert this code to the end of the file:
Code:
function TransferHangarItemToShipQuantity(int typeID, int quantity)
	{
		if !${Station.Docked}
		{
			/* TODO - Support picking up from entities in space */
			m_LastTransferComplete:Set[TRUE]
		}
		else
		{
			variable index:item cargoIndex
			variable iterator cargoIterator
			Me:GetHangarItems[cargoIndex]
			cargoIndex:GetIterator[cargoIterator]
			This.CargoToTransfer:Clear
		
			
			if ${cargoIterator:First(exists)}
			{
				do
				{
					if ${typeID} == ${cargoIterator.Value.TypeID}
					{
						UI:UpdateConsole["Transferiere ${quantity} * ${typeID}"]
						cargoIterator.Value:MoveTo[${MyShip.ID}, CargoHold, ${quantity}]
					}
				}
				while ${cargoIterator:Next(exists)}
			}
		}
	}
It's actually copy/paste from TransferHangarItemToShip but I only wanthed to transfer a certain amount of the item and I couldn't find a function for that (didn't really search for it also)

3.) obj_Missions.iss
change the complete function RunTradeMission(int agentID) to this:
Code:
	function RunTradeMission(int agentID)
	{
		variable int        QuantityRequired
		variable string     itemName
		variable bool       haveCargo = FALSE
		variable index:item CargoIndex
		variable iterator   CargoIterator
		variable int        TypeID
		variable float      itemVolume
		variable int        ItemQuantity

		Agents:SetActiveAgent[${Agent[id, ${agentID}].Name}]
		
		UI:UpdateConsole["Trade: Checking volume", LOG_CRITICAL]
		if ${This.MissionCache.Volume[${agentID}]} == 0
		{
			UI:UpdateConsole["Unknown Volume", LOG_CRITICAL]
			call Agents.MissionDetails
		}
		UI:UpdateConsole["Trade: Volume: ${This.MissionCache.Volume[${agentID}]}", LOG_CRITICAL]
		
		itemName:Set[${EVEDB_Items.Name[${This.MissionCache.TypeID[${agentID}]}]}]
		UI:UpdateConsole["Trade: ItemName: ${itemName} id: ${This.MissionCache.TypeID[${agentID}]}", LOG_CRITICAL]
		;UI:UpdateConsole["${EVEDB_Items.Volume[${This.MissionCache.TypeID[${agentID}]}]}", LOG_CRITICAL]
		
		itemVolume:Set[${EVEDB_Items.Volume[${This.MissionCache.TypeID[${agentID}]}]}]
		UI:UpdateConsole["Trade: itemVolume: ${itemVolume}", LOG_CRITICAL]
		UI:UpdateConsole["Trade: ${This.MissionCache.Volume[${agentID}]} / ${EVEDB_Items.Volume[${This.MissionCache.TypeID[${agentID}]}]} or ${itemVolume} = ${QuantityRequired}", LOG_CRITICAL]
		QuantityRequired:Set[${Math.Calc[(${This.MissionCache.Volume[${agentID}]})/${itemVolume}]}]
		call Cargo.CloseHolds
		call Cargo.OpenHolds

		;;; Check the cargohold of your ship
		MyShip:GetCargo[CargoIndex]
		CargoIndex:GetIterator[CargoIterator]
		if ${CargoIterator:First(exists)}
		{
			do
			{
				TypeID:Set[${CargoIterator.Value.TypeID}]
				ItemQuantity:Set[${CargoIterator.Value.Quantity}]
				UI:UpdateConsole["DEBUG: RunTradeMission: Ship's Cargo: ${ItemQuantity} units of ${CargoIterator.Value.Name}(${TypeID})."]

				if (${TypeID} == ${This.MissionCache.TypeID[${agentID}]}) && \
				   (${ItemQuantity} >= ${QuantityRequired})
				{
					UI:UpdateConsole["DEBUG: RunTradeMission: Found required items in ship's cargohold."]
					haveCargo:Set[TRUE]
				}
			}
			while ${CargoIterator:Next(exists)}
		}

		if ${This.MissionCache.Volume[${agentID}]} > ${Config.Missioneer.SmallHaulerLimit}
		{
			call Ship.ActivateShip "${Config.Missioneer.LargeHauler}"
		}
		else
		{
			call Ship.ActivateShip "${Config.Missioneer.SmallHauler}"
		}
		
		
		if ${haveCargo} == FALSE
		{
			UI:UpdateConsole["Trade: No Cargo", LOG_CRITICAL]
		
			variable index:item Items
			variable iterator Iter
			variable float iterquantity
			variable int destination
			variable bool havecargoinasset
			UI:UpdateConsole["Looking for ${QuantityRequired} ${This.MissionCache.TypeID[${agentID}]}", LOG_CRITICAL]
			Me:GetAssets[Items]
			Items:GetIterator[Iter]
			if ${Iter:First(exists)}
				do
				{
					if (${Iter.Value.TypeID} == ${This.MissionCache.TypeID[${agentID}]}) 
					{
						if (${Iter.Value.Quantity} >= ${QuantityRequired}) 
						{
							destination:Set[${Iter.Value.LocationID}]
							UI:UpdateConsole["Trade: Found Cargo in Asset ${Iter.Value.TypeID} X ${Iter.Value.Quantity} at ${destination}", LOG_CRITICAL]
							havecargoinasset:Set[TRUE]
						}
					}
				}
				while ${Iter:Next(exists)}
				UI:UpdateConsole["Trade2: Found Cargo in Asset ${Iter.Value.TypeID} X ${Iter.Value.Quantity}", LOG_CRITICAL]
				
			if ${havecargoinasset}
			{
							
				if ${Station.Docked}
				{
					call Station.Undock
				}
							
				UI:UpdateConsole["Trade: going to ${destination}", LOG_CRITICAL]
				;EVE.Station[${Iter.Value.LocationID}].SolarSystem:SetDestination
				call Ship.TravelToSystem  ${EVE.Station[${destination}].SolarSystem}
				UI:UpdateConsole["Trade: Traveling Done", LOG_CRITICAL]
				call Station.DockAtStation ${destination}
				UI:UpdateConsole["Trade: Docking Done", LOG_CRITICAL]
				
				call Cargo.TransferHangarItemToShipQuantity ${This.MissionCache.TypeID[${agentID}]} ${QuantityRequired}
				
				haveCargo:Set[TRUE]
			}
				UI:UpdateConsole["Trade: Checking Done", LOG_CRITICAL]]
		}
	
		;;; Check the hangar of the current station
		if ${haveCargo} == FALSE && ${Station.Docked}
		{
			Me:GetHangarItems[CargoIndex]
			CargoIndex:GetIterator[CargoIterator]

			if ${CargoIterator:First(exists)}
			{
				do
				{
					TypeID:Set[${CargoIterator.Value.TypeID}]
					ItemQuantity:Set[${CargoIterator.Value.Quantity}]
					UI:UpdateConsole["DEBUG: RunTradeMission: Station Hangar: ${ItemQuantity} units of ${CargoIterator.Value.Name}(${TypeID})."]

					if (${TypeID} == ${This.MissionCache.TypeID[${agentID}]}) && \
					   (${ItemQuantity} >= ${QuantityRequired})
					{
						UI:UpdateConsole["DEBUG: RunTradeMission: Found required items in station hangar."]
						if ${Agents.InAgentStation} == FALSE
						{
							call Cargo.TransferHangarItemToShip ${This.MissionCache.TypeID[${agentID}]}
						}
						haveCargo:Set[TRUE]
					}
				}
				while ${CargoIterator:Next(exists)}
			}
		}

		;;;  Try to buy the item
		if ${haveCargo} == FALSE
		{
		  	if ${Station.Docked}
		  	{
			 	call Station.Undock
		  	}
			UI:UpdateConsole["obj_Missions: Need Cargo quantitiy: ${quantity} Pieces"]
			UI:UpdateConsole["obj_Missions: Need Cargo QuantityRequired: ${QuantityRequired} Pieces"]
			call Market.GetMarketOrders ${This.MissionCache.TypeID[${agentID}]}
			;call Market.FindBestWeightedSellOrder ${Config.Missioneer.AvoidLowSec} ${quantity}
			call Market.FindBestWeightedSellOrder ${Config.Missioneer.AvoidLowSec} ${QuantityRequired}
			call Ship.TravelToSystem ${Market.BestSellOrderSystem}
			call Station.DockAtStation ${Market.BestSellOrderStation}
			;call Market.PurchaseItem ${This.MissionCache.TypeID[${agentID}]} ${quantity}
			call Market.PurchaseItem ${This.MissionCache.TypeID[${agentID}]} ${QuantityRequired}

			call Cargo.TransferHangarItemToShip ${This.MissionCache.TypeID[${agentID}]}

			if ${Cargo.LastTransferComplete} == FALSE
			{
				UI:UpdateConsole["obj_Missions: ERROR: Couldn't carry all the trade goods!  Pausing script!!"]
				Script:Pause
			}
		}

		;;;UI:UpdateConsole["obj_Missions: MoveTo Agent"]
		call Agents.MoveTo
		wait 50
		;;;call Cargo.TransferItemTypeToHangar ${This.MissionCache.TypeID[${agentID}]}
		;;;wait 50

		UI:UpdateConsole["obj_Missions: TurnInMission"]
		call Agents.TurnInMission
	}
4.) obj_Market.iss
just in you haven't done that already, change
Code:
EVE:UpdateMarketOrders_A[${typeID}]
wait 40
EVE:UpdateMarketOrders_B[${typeID}]
wait 10
to
Code:
EVE:FetchMarketOrders[${typeID}]
wait 40
;EVE:UpdateMarketOrders_B[${typeID}]
;wait 10
It should let you buy stuff from the market. I haven't tried that one yet because I always have enough ore (thanks to evebot)

that's it actually ...
the code could use some finetuning. Some debug texts return some wrong values - just ignore them and see if the bot is working as intened.
 

Dixi

Active Member
for the "Me:GetAssets[Items]"-function you will have to keep your Personal Asset window open at all times. You will also have to expand all (?) of the stations listed in the Personal Asset window. Only then will the GetAssets function fetch all the assets and find the required item.
 
Top Bottom