Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rework user callsign handling, load call history file at runtime #134

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions ArrlFd.pas
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ function TArrlFieldDay.LoadCallHistory(const AUserCallsign : string) : boolean;
end;
end;

// retain user's callsign after successful load
SetUserCallsign(AUserCallsign);
Result := True;

finally
Expand Down
2 changes: 0 additions & 2 deletions CWOPS.pas
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ function TCWOPS.LoadCallHistory(const AUserCallsign : string) : boolean;
end;
end;

// retain user's callsign after successful load
SetUserCallsign(AUserCallsign);
Result := True;

finally
Expand Down
107 changes: 91 additions & 16 deletions Contest.pas
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@
interface

uses
SysUtils, SndTypes, Station, StnColl, MyStn, Math, Ini, System.Classes,
MovAvg, Mixers, VolumCtl, RndFunc, TypInfo, DxStn, DxOper, Log;
SndTypes, Station, StnColl, MyStn, Ini, System.Classes,
MovAvg, Mixers, VolumCtl, DxStn;

type
TContest = class
private
UserCallsign : String; // used by LoadCallHistory() to minimize reloads
LastLoadCallsign : String; // used to minimize call history file reloads

function DxCount: integer;
procedure SwapFilters;

protected
constructor Create;
function HasUserCallsignChanged(const AUserCallsign : String) : boolean;
procedure SetUserCallsign(const AUserCallsign : String);
function IsReloadRequired(const AUserCallsign : String) : boolean;
procedure SetLastLoadCallsign(const AUserCallsign : String);

public
BlockNumber: integer;
Expand All @@ -36,7 +36,7 @@ TContest = class

destructor Destroy; override;
procedure Init;
function LoadCallHistory(const AHomeCallsign : string) : boolean; virtual; abstract;
function LoadCallHistory(const AUserCallsign : string) : boolean; virtual; abstract;

function PickStation : integer; virtual; abstract;
procedure DropStation(id : integer); virtual; abstract;
Expand All @@ -45,13 +45,20 @@ TContest = class
function GetStationInfo(const ACallsign : string) : string; virtual;
function PickCallOnly : string;

function OnSetMyCall(const AUserCallsign : string; out err : string) : boolean; virtual;
function OnContestPrepareToStart(const AUserCallsign: string;
const ASentExchange : string) : Boolean; virtual;
function GetSentExchTypes(
const AStationKind : TStationKind;
const AMyCallsign : string) : TExchTypes;
function GetRecvExchTypes(
const AStationKind : TStationKind;
const AMyCallsign : string;
const ADxCallsign : string) : TExchTypes;
function GetExchangeTypes(
const AStationKind : TStationKind;
const AMsgType : TRequestedMsgType;
const ADxCallsign : string) : TExchTypes; virtual;
function Minute: Single;
function GetAudio: TSingleArray;
procedure OnMeFinishedSending;
Expand All @@ -65,6 +72,7 @@ TContest = class
implementation

uses
SysUtils, RndFunc, Math, DxOper, Log,
Main, CallLst, ARRL;

{ TContest }
Expand Down Expand Up @@ -96,7 +104,7 @@ constructor TContest.Create;
Agc.HoldSamples := 155;
Agc.AgcEnabled := true;
NoActivityCnt :=0;
UserCallsign := '';
LastLoadCallsign := '';

Init;
end;
Expand All @@ -119,21 +127,26 @@ procedure TContest.Init;
Me.Init;
Stations.Clear;
BlockNumber := 0;
UserCallsign := '';
LastLoadCallsign := '';
end;


{ return whether to call history file is valid based on user's callsign. }
function TContest.HasUserCallsignChanged(const AUserCallsign : string) : boolean;
{
user's home callsign is required when loading some contests
(don't load if user callsign is empty or is the same as last time).

return whether the call history file is valid. This varies by contest.
}
function TContest.IsReloadRequired(const AUserCallsign : string) : boolean;
begin
// user's home callsign is required to load this contest.
Result := (not AUserCallsign.IsEmpty) and (UserCallsign <> AUserCallsign);
Result := not (AUserCallsign.IsEmpty or (LastLoadCallsign = AUserCallsign));
end;


procedure TContest.SetUserCallsign(const AUserCallsign : String);
// called by LoadCallHistory after loading the call history file.
procedure TContest.SetLastLoadCallsign(const AUserCallsign : String);
begin
UserCallsign := AUserCallsign;
LastLoadCallsign := AUserCallsign;
end;


Expand All @@ -159,15 +172,67 @@ function TContest.PickCallOnly : string;
end;


{
OnSetMyCall() is called whenever the user's callsign is set.
Can be overriden by derived classes as needed to update contest-specific
settings. Note that derived classes should update contest-specific
settings before calling this function since the Sent Exchange settings
may depend upon this contest-specific information.

Returns whether the call was successful.
}
function TContest.OnSetMyCall(const AUserCallsign : string; out err : string) : boolean;
begin
Me.MyCall:= AUserCallsign;

// update my sent exchange field types
Me.SentExchTypes:= GetSentExchTypes(skMyStation, AUserCallsign);

Result:= True;
end;


{
OnContestPrepareToStart() event is called whenever a contest is started.
Some contests will override this method to provide additional contest-specfic
behaviors. When overriding this function, be sure to call this base-class
function.

Current behavior is to load the call history file. This action has been
defferred until now since some contests use the user's callsign to determine
which stations can work other stations in the contest. For example, in the
ARRL DX Contest, US/CA Stations work DX (non-US/CA) stations.

Returns whether the operation was successfull.
}
function TContest.OnContestPrepareToStart(const AUserCallsign: string;
const ASentExchange : string) : Boolean;
begin
// reload call history iff user's callsign has changed.
if IsReloadRequired(AUserCallsign) then
begin
// load contest-specific call history file
Result:= LoadCallHistory(AUserCallsign);

// retain user's callsign after successful load
if Result then
SetLastLoadCallsign(AUserCallsign);
end
else
Result:= True;
end;


{
Return sent dynamic exchange types for the given kind-of-station and callsign.
AStationKind represents either the user's station (representing current
simulation) or the DxStn represented a simulated station calling the user.
}
function TContest.GetSentExchTypes(
const AStationKind : TStationKind;
const AMyCallsign : string) : TExchTypes;
begin
Result.Exch1 := ActiveContest.ExchType1;
Result.Exch2 := ActiveContest.ExchType2;
Result:= Self.GetExchangeTypes(AStationKind, mtSendMsg, {ADxCallsign=}'');
end;


Expand All @@ -180,6 +245,16 @@ function TContest.GetRecvExchTypes(
const AStationKind : TStationKind;
const AMyCallsign : string;
const ADxCallsign : string) : TExchTypes;
begin
// perhaps need to pass in AUserCallsign instead of using TArrlDx.HomeCallIsWVE
Result:= Self.GetExchangeTypes(AStationKind, mtRecvMsg, ADxCallsign);
end;


function TContest.GetExchangeTypes(
const AStationKind : TStationKind;
const AMsgType : TRequestedMsgType;
const ADxCallsign : string) : TExchTypes;
begin
Result.Exch1 := ActiveContest.ExchType1;
Result.Exch2 := ActiveContest.ExchType2;
Expand Down
2 changes: 0 additions & 2 deletions CqWW.pas
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ function TCqWw.LoadCallHistory(const AUserCallsign : string) : boolean;
end;
end;

// retain user's callsign after successful load
SetUserCallsign(AUserCallsign);
Result := True;

finally
Expand Down
2 changes: 0 additions & 2 deletions CqWpx.pas
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ function TCqWpx.LoadCallHistory(const AUserCallsign : string) : boolean;

CallLst.LoadCallList;

// retain user's callsign after successful load
SetUserCallsign(AUserCallsign);
Result := True;
end;

Expand Down
3 changes: 3 additions & 0 deletions Ini.pas
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ TContestDefinition = record
PContestDefinition = ^TContestDefinition;

const
UndefExchType1 : TExchange1Type = TExchange1Type(-1);
UndefExchType2 : TExchange2Type = TExchange2Type(-1);

{
Each contest is declared here. Long-term, this will be a generalized
table-driven implementation allowing new contests to be configured
Expand Down
1 change: 1 addition & 0 deletions Main.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,7 @@ object MainForm: TMainForm
TabOrder = 0
Text = 'VE3NEA'
OnChange = Edit4Change
OnExit = Edit4Exit
end
object SpinEdit1: TSpinEdit
Left = 91
Expand Down
Loading