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

Introduce class hierarchy to support common Contest behaviors #125

Merged
merged 6 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
55 changes: 33 additions & 22 deletions ArrlFd.pas
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
interface

uses
Generics.Defaults, Generics.Collections, ARRL,
SysUtils, Classes, {Contnrs,} PerlRegEx, pcre;
Generics.Defaults, Generics.Collections, Contest, DxStn;

type
TFdCallRec = class
Expand All @@ -21,42 +20,38 @@ TFdCallRec = class
class function compareCall(const left, right: TFdCallRec) : integer; static;
end;

TArrlFieldDay = class
TArrlFieldDay = class(TContest)
private
FdCallList: TObjectList<TFdCallRec>;
Comparer: IComparer<TFdCallRec>;

procedure LoadFdHistoryFile;

public
constructor Create;
destructor Destroy; override;
function pickStation(): integer;
//function getcwopsid(): integer;
//function getcwopscall(id:integer): string;
//function getcwopsname(id:integer): string;
//function getcwopsnum(id:integer): integer;
function getCall(id:integer): string; // returns station callsign
procedure LoadCallHistory(const AUserCallsign : string); override;

function PickStation(): integer; override;
procedure DropStation(id : integer); override;
function GetCall(id : integer): string; override; // returns station callsign
procedure GetExchange(id : integer; out station : TDxStation); override;

function getExch1(id:integer): string; // returns station info (e.g. 3A)
function getExch2(id:integer): string; // returns section info (e.g. OR)
function getClass(id:integer): string; // returns station class (e.g. 3A)
function getSection(id:integer): string; // returns section (e.g. OR)
function getUserText(id:integer): string; // returns optional club name
//function IsNum(Num: String): Boolean;
function FindCallRec(out fdrec: TFdCallRec; const ACall: string): Boolean;
function GetStationInfo(const ACallsign: string) : string;
function GetStationInfo(const ACallsign: string) : string; override;
end;

var
gARRLFD: TArrlFieldDay;


implementation

uses
log;
SysUtils, Classes, Log, PerlRegEx, pcre, ARRL;

procedure TArrlFieldDay.LoadFdHistoryFile;
procedure TArrlFieldDay.LoadCallHistory(const AUserCallsign : string);
const
DelimitChar: char = ',';
var
Expand All @@ -70,7 +65,7 @@ procedure TArrlFieldDay.LoadFdHistoryFile;
tl.StrictDelimiter := True;

try
FdCallList:= TObjectList<TFdCallRec>.Create;
FdCallList.Clear;

slst.LoadFromFile(ParamStr(1) + 'FD_2022-004.TXT');

Expand Down Expand Up @@ -106,8 +101,8 @@ procedure TArrlFieldDay.LoadFdHistoryFile;
constructor TArrlFieldDay.Create;
begin
inherited Create;
FdCallList:= TObjectList<TFdCallRec>.Create;
Comparer := TComparer<TFdCallRec>.Construct(TFdCallRec.compareCall);
LoadFdHistoryFile;
end;


Expand All @@ -118,12 +113,19 @@ destructor TArrlFieldDay.Destroy;
end;


function TArrlFieldDay.pickStation(): integer;
function TArrlFieldDay.PickStation(): integer;
begin
result := random(FdCallList.Count);
end;


procedure TArrlFieldDay.DropStation(id : integer);
begin
assert(id < FdCallList.Count);
FdCallList.Delete(id);
end;


function TArrlFieldDay.FindCallRec(out fdrec: TFdCallRec; const ACall: string): Boolean;
var
rec: TFdCallRec;
Expand Down Expand Up @@ -163,7 +165,7 @@ function TArrlFieldDay.GetStationInfo(const ACallsign: string) : string;
dxEntity := '';
result:= '';

if gArrlFd.FindCallRec(fdrec, ACallsign) then
if FindCallRec(fdrec, ACallsign) then
begin
userText:= fdrec.UserText;

Expand All @@ -184,12 +186,21 @@ function TArrlFieldDay.GetStationInfo(const ACallsign: string) : string;
end;


function TArrlFieldDay.getCall(id:integer): string; // returns station callsign
// returns station callsign
function TArrlFieldDay.GetCall(id : integer): string;
begin
result := FdCallList.Items[id].Call;
end;


procedure TArrlFieldDay.GetExchange(id : integer; out station : TDxStation);
begin
station.Exch1 := getExch1(id);
station.Exch2 := getExch2(id);
station.UserText := getUserText(id);
end;


function TArrlFieldDay.getExch1(id:integer): string; // returns station info (e.g. 3A)
begin
result := FdCallList.Items[id].StnClass;
Expand Down
54 changes: 39 additions & 15 deletions CWOPS.pas
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
interface

uses
SysUtils, Classes, Contnrs, PerlRegEx, pcre;
Classes, Contest, Contnrs, DxStn;

type
TCWOPSRec= class
Expand All @@ -13,31 +13,34 @@ TCWOPSRec= class
Number: string;
end;

TCWOPS= class
TCWOPS= class(TContest)
private
CWOPSList: TList;
procedure LoadCWOPS;
procedure Delimit(var AStringList: TStringList; const AText: string);

public
constructor Create;
function getcwopsid(): integer;
function getcwopscall(id:integer): string;
destructor Destroy; override;
procedure LoadCallHistory(const AUserCallsign : string); override;

function PickStation(): integer; override;
procedure DropStation(id : integer); override;
function GetCall(id : integer): string; override;
procedure GetExchange(id : integer; out station : TDxStation); override;

function getcwopsname(id:integer): string;
function getcwopsnum(id:integer): integer;
function IsNum(Num: String): Boolean;
end;

var
CWOPSCWT: TCWOPS;
function IsNum(Num: String): Boolean;


implementation

uses
log;
SysUtils, Log;

procedure TCWOPS.LoadCWOPS;
procedure TCWOPS.LoadCallHistory(const AUserCallsign : string);
var
slst, tl: TStringList;
i: integer;
Expand All @@ -46,7 +49,7 @@ procedure TCWOPS.LoadCWOPS;
slst:= TStringList.Create;
tl:= TStringList.Create;
try
CWOPSList:= TList.Create;
CWOPSList.Clear;
slst.LoadFromFile(ParamStr(1) + 'CWOPS.LIST');
slst.Sort;

Expand Down Expand Up @@ -81,21 +84,42 @@ procedure TCWOPS.LoadCWOPS;
constructor TCWOPS.Create;
begin
inherited Create;
LoadCWOPS;
CWOPSList:= TList.Create;
end;

destructor TCWOPS.Destroy;
begin
FreeAndNil(CWOPSList);
inherited;
end;

function TCWOPS.getcwopsid(): integer;

function TCWOPS.PickStation(): integer;
begin
result := random(CWOPSList.Count);
end;


function TCWOPS.getcwopscall(id:integer): string;
procedure TCWOPS.DropStation(id : integer);
begin
assert(id < CWOPSList.Count);
CWOPSList.Delete(id);
end;


function TCWOPS.GetCall(id : integer): string;
begin
result := TCWOPSRec(CWOPSList.Items[id]).Call;
end;


procedure TCWOPS.GetExchange(id : integer; out station : TDxStation);
begin
station.OpName := getcwopsname(id);
station.NR := getcwopsnum(id);
end;


function TCWOPS.getcwopsname(id:integer): string;

begin
Expand All @@ -108,7 +132,7 @@ function TCWOPS.getcwopsnum(id:integer): integer;
result := strtoint(TCWOPSRec(CWOPSList.Items[id]).Number);
end;

function TCWOPS.IsNum(Num: String): Boolean;
function IsNum(Num: String): Boolean;
var
X : Integer;
begin
Expand Down
38 changes: 28 additions & 10 deletions CallLst.pas
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,34 @@
interface

uses
SysUtils, Classes, Ini;

procedure LoadCallList;
function PickCall: string;
Classes;

type
// simple calllist. contains a TStringList of callsigns.
TCallList = class
protected
Calls: TStringList;

public
constructor Create;
destructor Destroy; override;
procedure LoadCallList;
function PickCall : string;
end;

var
Calls: TStringList;

implementation

uses
SysUtils, Ini;

function CompareCalls(Item1, Item2: Pointer): Integer;
begin
Result := StrComp(PChar(Item1), PChar(Item2));
end;

procedure LoadCallList;
// reads callsigns from Master.dta file
procedure TCallList.LoadCallList;
const
Chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/';
CHRCOUNT = Length(Chars);
Expand Down Expand Up @@ -89,7 +101,8 @@ procedure LoadCallList;
end;


function PickCall: string;
// returns a single callsign
function TCallList.PickCall : string;
var
Idx: integer;
begin
Expand All @@ -106,11 +119,16 @@ function PickCall: string;
end;


initialization
constructor TCallList.Create;
begin
Calls := TStringList.Create;
end;

finalization
destructor TCallList.Destroy;
begin
Calls.Free;
end;


end.

36 changes: 34 additions & 2 deletions Contest.pas
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ TContest = class
private
function DxCount: integer;
procedure SwapFilters;
protected
constructor Create;
public
BlockNumber: integer;
Me: TMyStation;
Expand All @@ -26,9 +28,17 @@ TContest = class
RitPhase: Single;
FStopPressed: boolean;

constructor Create;
destructor Destroy; override;
procedure Init;
procedure LoadCallHistory(const AUserCallsign : string); virtual; abstract;

function PickStation : integer; virtual; abstract;
procedure DropStation(id : integer); virtual; abstract;
function GetCall(id : integer) : string; virtual; abstract;
procedure GetExchange(id : integer; out station : TDxStation); virtual; abstract;
function GetStationInfo(const ACallsign : string) : string; virtual;
function PickCallOnly : string;

function GetSentExchTypes(
const AStationKind : TStationKind;
const AMyCallsign : string) : TExchTypes;
Expand All @@ -49,7 +59,7 @@ TContest = class
implementation

uses
Main;
Main, CallLst, ARRL;

{ TContest }

Expand Down Expand Up @@ -105,6 +115,28 @@ procedure TContest.Init;
end;


{
GetStationInfo() returns station's DXCC information.

Adding a contest: UpdateSbar - update status bar with station info (e.g. FD shows UserText)
Override as needed for each contest.
}
function TContest.GetStationInfo(const ACallsign : string) : string;
begin
Result := gDXCCList.Search(ACallsign);
end;


// helper function to return only a callsign (used by QrnStation)
function TContest.PickCallOnly : string;
var
id : integer;
begin
id := PickStation;
Result := GetCall(id);
end;


{
Return sent dynamic exchange types for the given kind-of-station and callsign.
}
Expand Down
Loading