Skip to content

Commit

Permalink
Fix for gates present while salvaging
Browse files Browse the repository at this point in the history
  • Loading branch information
chantling committed Jun 1, 2011
1 parent 0db8379 commit 0492cea
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Questor.Modules/Panic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Panic
private double _lastNormalY;
private double _lastNormalZ;

private DateTime _nextRepairAction;
//private DateTime _nextRepairAction;

public PanicState State { get; set; }

Expand Down
11 changes: 8 additions & 3 deletions Questor.Modules/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ public Settings()
public bool DebugPerformance { get; set; }

public bool AutoStart { get; set; }
public bool waitDecline { get; set; }
public bool waitDecline { get; set; }
public int RandomDelay { get; set; }
public float minStandings { get; set; }
public float minStandings { get; set; }
public bool UseGatesInSalvage { get; set; }

public bool EnableStorylines { get; set; }

Expand Down Expand Up @@ -180,6 +181,8 @@ public void LoadSettings()
DroneRecallCapacitorPct = 0;
LongRangeDroneRecallCapacitorPct = 0;

UseGatesInSalvage = false;

Blacklist.Clear();
FactionBlacklist.Clear();

Expand All @@ -194,7 +197,9 @@ public void LoadSettings()
AutoStart = (bool?) xml.Element("autoStart") ?? false;
waitDecline = (bool?) xml.Element("waitDecline") ?? false;
RandomDelay = (int?) xml.Element("randomDelay") ?? 0;
minStandings = (float?) xml.Element("minStandings") ?? 10;
minStandings = (float?) xml.Element("minStandings") ?? 10;

UseGatesInSalvage = (bool?)xml.Element("useGatesInSalvage") ?? false;

EnableStorylines = (bool?) xml.Element("enableStorylines") ?? false;

Expand Down
119 changes: 112 additions & 7 deletions Questor/Questor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ namespace Questor
using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;
using DirectEve;
using global::Questor.Modules;
using global::Questor.Storylines;

public class Questor
{
private frmMain m_Parent;
private AgentInteraction _agentInteraction;
private Arm _arm;
private Combat _combat;
Expand All @@ -40,8 +42,13 @@ public class Questor
private Random _random;
private int _randomDelay;

public Questor()
private double _lastX;
private double _lastY;
private double _lastZ;

public Questor(frmMain form1)
{
m_Parent = form1;
_lastPulse = DateTime.MinValue;

_random = new Random();
Expand Down Expand Up @@ -144,6 +151,10 @@ private void OnFrame(object sender, EventArgs e)
if (!Cache.Instance.DirectEve.Session.IsReady)
return;

// If Questor window not visible, show it
if (!m_Parent.Visible)
m_Parent.Visible = true;

// We are not in space or station, don't do shit yet!
if (!Cache.Instance.InSpace && !Cache.Instance.InStation)
return;
Expand Down Expand Up @@ -631,10 +642,11 @@ private void OnFrame(object sender, EventArgs e)

case QuestorState.GotoSalvageBookmark:
_traveler.ProcessState();
if (_traveler.State == TravelerState.AtDestination)
string target = "Acceleration Gate";
var targets = Cache.Instance.EntitiesByName(target);
if (_traveler.State == TravelerState.AtDestination || GateInSalvage())
{
State = QuestorState.Salvage;

_traveler.Destination = null;
}

Expand Down Expand Up @@ -664,28 +676,47 @@ private void OnFrame(object sender, EventArgs e)
{
Logging.Log("Salvage: Finished salvaging the room");

bool GatesInRoom = GateInSalvage();
var bookmarks = Cache.Instance.BookmarksByLabel(Settings.Instance.BookmarkPrefix + " ");
do
{
// Remove all bookmarks from address book
var bookmark = bookmarks.FirstOrDefault(b => Cache.Instance.DistanceFromMe(b.X ?? 0, b.Y ?? 0, b.Z ?? 0) < 250000);
if (GatesInRoom) // if there're gates in the room, delete all bookmarks
bookmark = bookmarks.FirstOrDefault();
if (bookmark == null)
break;

bookmark.Delete();
bookmarks.Remove(bookmark);
} while (true);

if (bookmarks.Count == 0)
if (bookmarks.Count == 0 && !GatesInRoom)
{
Logging.Log("Salvage: We have salvaged all bookmarks, goto base");
State = QuestorState.GotoBase;
}
else
{
Logging.Log("Salvage: Goto the next salvage bookmark");
_traveler.Destination = new BookmarkDestination(bookmarks.OrderBy(b => b.CreatedOn).First());
State = QuestorState.GotoSalvageBookmark;

if (!GatesInRoom)
{
Logging.Log("Salvage: Goto the next salvage bookmark");

State = QuestorState.GotoSalvageBookmark;
_traveler.Destination = new BookmarkDestination(bookmarks.OrderBy(b => b.CreatedOn).First());
}
else if (Settings.Instance.UseGatesInSalvage)
{
Logging.Log("Salvage: Acceleration gate found - moving to next pocket");
State = QuestorState.SalvageUseGate;
}
else
{
Logging.Log("Salvage: Acceleration gate found, useGatesInSalvage set to false - Returning to base");
State = QuestorState.GotoBase;
_traveler.Destination = null;
}
}
break;
}
Expand Down Expand Up @@ -715,6 +746,70 @@ private void OnFrame(object sender, EventArgs e)
}
break;


case QuestorState.SalvageUseGate:

target = "Acceleration Gate";

targets = Cache.Instance.EntitiesByName(target);
if (targets == null || targets.Count() == 0)
{
State = QuestorState.GotoSalvageBookmark;
return;
}

_lastX = Cache.Instance.DirectEve.ActiveShip.Entity.X;
_lastY = Cache.Instance.DirectEve.ActiveShip.Entity.Y;
_lastZ = Cache.Instance.DirectEve.ActiveShip.Entity.Z;

var closest = targets.OrderBy(t => t.Distance).First();
if (closest.Distance < 2500)
{
Logging.Log("Salvage: Acceleration gate found - GroupID=" + closest.GroupId);

// Activate it and move to the next Pocket
closest.Activate();

// Do not change actions, if NextPocket gets a timeout (>2 mins) then it reverts to the last action
Logging.Log("Salvage: Activate [" + closest.Name + "] and change state to 'NextPocket'");

State = QuestorState.SalvageNextPocket;
_lastPulse = DateTime.Now;
}
else if (closest.Distance < 150000)
{
// Move to the target
if (Cache.Instance.Approaching == null || Cache.Instance.Approaching.Id != closest.Id)
{
Logging.Log("Salvage: Approaching target [" + closest.Name + "][" + closest.Id + "]");
closest.Approach();
}
}
else
{
// Probably never happens
closest.WarpTo();
}
_lastPulse = DateTime.Now.AddSeconds(10);
break;

case QuestorState.SalvageNextPocket:
var distance = Cache.Instance.DistanceFromMe(_lastX, _lastY, _lastZ);
if (distance > 100000)
{
Logging.Log("Salvage: We've moved to the next Pocket [" + distance + "]");

State = QuestorState.Salvage;
}
else if (DateTime.Now.Subtract(_lastPulse).TotalMinutes > 2)
{
Logging.Log("Salvage: We've timed out, retry last action");

// We have reached a timeout, revert to ExecutePocketActions (e.g. most likely Activate)
State = QuestorState.SalvageUseGate;
}
break;

case QuestorState.Storyline:
_storyline.ProcessState();

Expand All @@ -728,5 +823,15 @@ private void OnFrame(object sender, EventArgs e)
break;
}
}

private bool GateInSalvage()
{
string target = "Acceleration Gate";

var targets = Cache.Instance.EntitiesByName(target);
if (targets == null || targets.Count() == 0)
return false;
return true;
}
}
}
2 changes: 2 additions & 0 deletions Questor/QuestorState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public enum QuestorState
UnloadLoot,
BeginAfterMissionSalvaging,
GotoSalvageBookmark,
SalvageUseGate,
SalvageNextPocket,
Salvage,
Error,
Panic,
Expand Down
2 changes: 1 addition & 1 deletion Questor/frmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public frmMain()
foreach (var text in Enum.GetNames(typeof(QuestorState)))
QuestorStateComboBox.Items.Add(text);

_questor = new Questor();
_questor = new Questor(this);
}

private void tUpdateUI_Tick(object sender, EventArgs e)
Expand Down
15 changes: 15 additions & 0 deletions changelog - chant.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
June 01, 2011:
* Changes/Fixes to Questor:
- Merged Da_Teach's Incursion 1.6 fix to DirectEve.dll

May 30, 2011:
* Changes/Fixes to Questor:
- Added in code to check for acceleration gates during salvage because pockets didn't despawn
on mission turn-in. bool <useGatesInSalvage> in char.xml determines behavior when gates
detected; if false, Questor salvages any ships in first pocket, then quits salvaging and
returns to base. If true, Questor salvages, then proceeds through the gates, salvaging as
it goes.
- Attempt to fix issue with the Questor window occasionally disappearing, leaving Questor running
but with no ability to control it.


May 28, 2011:
* Changes/Fixes to Questor:
- Merged in Ganondorf's fitting swap code
Expand Down

0 comments on commit 0492cea

Please sign in to comment.