namespace XFEEDToolBox.Plugin;
internal static unsafe partial class Navigation
{
// The server quote belongs to this exact docked ship, independently of
// the shared request/receipt slot used by subsequent trade operations.
private struct ServiceQuoteSnapshot
{
internal CommerceReadRequest source;
internal string? body;
internal uint consumed;
}
private static ServiceQuoteSnapshot serviceQuoteSnapshot;
private static bool ServiceQuoteMatches(in ServiceQuoteSnapshot quote,in Snapshot frame,nuint backend,uint market,ulong generation,uint kind,ulong now,ulong epoch)
=>kind is >=4 and <=7&"e.body is {Length:>0}&"e.source.kind==3&"e.source.state==3
&"e.source.generation==generation&&generation!=0&"e.source.market==market&"e.source.maintenance==backend
&"e.source.entity==frame.entity&"e.source.life==frame.life&"e.source.epoch==epoch
&&now>=quote.source.observed&&now-quote.source.observed<=30000&&(quote.consumed&(1u<<(int)kind))==0;
private static void CaptureServiceQuote(in CommerceReadRequest work,string body)
{
if(work.kind==3&&work.state==3&&body.Length!=0)serviceQuoteSnapshot=new(){source=work,body=body};
}
private static uint ServiceQuotesSelfTest()
{
var frame=new Snapshot{entity=12,life=34};
var quote=new ServiceQuoteSnapshot{source=new(){generation=5,entity=12,life=34,epoch=7,kind=3,state=3,market=42,maintenance=56,observed=100},body="original"};
bool Matches(ServiceQuoteSnapshot value,Snapshot actual,nuint backend=56,uint market=42,ulong generation=5,uint kind=4,ulong now=101,ulong epoch=7)
=>ServiceQuoteMatches(value,actual,backend,market,generation,kind,now,epoch);
uint passed=0;
if(Matches(quote,frame)&&Matches(quote,frame,kind:7))passed|=1;
if(!Matches(quote,frame,generation:4)&&!Matches(quote,frame,generation:0))passed|=2;
if(!Matches(quote,frame,market:43)&&!Matches(quote,frame,backend:57))passed|=4;
if(!Matches(quote,new Snapshot{entity=13,life=34})&&!Matches(quote,new Snapshot{entity=12,life=35}))passed|=8;
if(!Matches(quote,frame,epoch:8)&&!Matches(quote,frame,now:99)&&!Matches(quote,frame,now:30101))passed|=16;
quote.consumed=1u<<4;if(!Matches(quote,frame)&&Matches(quote,frame,kind:5))passed|=32;quote.consumed=0;
quote.source.kind=1;if(!Matches(quote,frame))passed|=64;quote.source.kind=3;
quote.source.state=4;if(!Matches(quote,frame)&&!Matches(quote,frame,kind:3)&&!Matches(quote,frame,kind:8))passed|=128;
return passed;
}
#if PLUGIN_NAVIGATION
[UnmanagedCallersOnly(EntryPoint="XFENavigationServiceQuotesSelfTest")]
internal static uint ExportServiceQuotesSelfTest()=>RunTest(ServiceQuotesSelfTest);
#endif
}
namespace XFEEDToolBox.Plugin;
internal static unsafe partial class Navigation
{
// The server quote belongs to this exact docked ship, independently of
// the shared request/receipt slot used by subsequent trade operations.
private struct ServiceQuoteSnapshot
{
internal CommerceReadRequest source;
internal string? body;
internal uint consumed;
}
private static ServiceQuoteSnapshot serviceQuoteSnapshot;
private static bool ServiceQuoteMatches(in ServiceQuoteSnapshot quote,in Snapshot frame,nuint backend,uint market,ulong generation,uint kind,ulong now,ulong epoch)
=>kind is >=4 and <=7&"e.body is {Length:>0}&"e.source.kind==3&"e.source.state==3
&"e.source.generation==generation&&generation!=0&"e.source.market==market&"e.source.maintenance==backend
&"e.source.entity==frame.entity&"e.source.life==frame.life&"e.source.epoch==epoch
&&now>=quote.source.observed&&now-quote.source.observed<=30000&&(quote.consumed&(1u<<(int)kind))==0;
private static void CaptureServiceQuote(in CommerceReadRequest work,string body)
{
if(work.kind==3&&work.state==3&&body.Length!=0)serviceQuoteSnapshot=new(){source=work,body=body};
}
private static uint ServiceQuotesSelfTest()
{
var frame=new Snapshot{entity=12,life=34};
var quote=new ServiceQuoteSnapshot{source=new(){generation=5,entity=12,life=34,epoch=7,kind=3,state=3,market=42,maintenance=56,observed=100},body="original"};
bool Matches(ServiceQuoteSnapshot value,Snapshot actual,nuint backend=56,uint market=42,ulong generation=5,uint kind=4,ulong now=101,ulong epoch=7)
=>ServiceQuoteMatches(value,actual,backend,market,generation,kind,now,epoch);
uint passed=0;
if(Matches(quote,frame)&&Matches(quote,frame,kind:7))passed|=1;
if(!Matches(quote,frame,generation:4)&&!Matches(quote,frame,generation:0))passed|=2;
if(!Matches(quote,frame,market:43)&&!Matches(quote,frame,backend:57))passed|=4;
if(!Matches(quote,new Snapshot{entity=13,life=34})&&!Matches(quote,new Snapshot{entity=12,life=35}))passed|=8;
if(!Matches(quote,frame,epoch:8)&&!Matches(quote,frame,now:99)&&!Matches(quote,frame,now:30101))passed|=16;
quote.consumed=1u<<4;if(!Matches(quote,frame)&&Matches(quote,frame,kind:5))passed|=32;quote.consumed=0;
quote.source.kind=1;if(!Matches(quote,frame))passed|=64;quote.source.kind=3;
quote.source.state=4;if(!Matches(quote,frame)&&!Matches(quote,frame,kind:3)&&!Matches(quote,frame,kind:8))passed|=128;
return passed;
}
#if PLUGIN_NAVIGATION
[UnmanagedCallersOnly(EntryPoint="XFENavigationServiceQuotesSelfTest")]
internal static uint ExportServiceQuotesSelfTest()=>RunTest(ServiceQuotesSelfTest);
#endif
}