hedgewars/uFLGameConfig.pas
author unc0rr
Sun, 28 Sep 2014 00:18:01 +0400
branchqmlfrontend
changeset 10426 727a154cf784
parent 10406 b5fd52ac760f
child 10428 7c25297720f1
permissions -rw-r--r--
Some refactoring
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10406
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
     1
unit uFLGameConfig;
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
     2
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
     3
interface
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
     4
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
     5
procedure resetGameConfig; cdecl; export;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
     6
procedure runQuickGame; cdecl; export;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
     7
procedure getPreview; cdecl; export;
10406
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
     8
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
     9
implementation
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
    10
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    11
const
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    12
    MAXCONFIGS = 5;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    13
    MAXARGS = 32;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    14
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    15
type
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    16
    TGameType = (gtPreview, gtLocal);
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    17
    THedgehog = record
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    18
            name: shortstring;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    19
            hat: shortstring;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    20
            end;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    21
    TTeam = record
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    22
            teamName: shortstring;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    23
            flag: shortstring;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    24
            graveName: shortstring;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    25
            fortName: shortstring;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    26
            owner: shortstring;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    27
            extDriven: boolean;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    28
            botLevel: Longword;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    29
            hedgehogs: array[0..7] of THedgehog;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    30
            hogsNumber: Longword;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    31
            end;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    32
    TGameConfig = record
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    33
            seed: shortstring;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    34
            theme: shortstring;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    35
            script: shortstring;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    36
            gameType: TGameType;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    37
            teams: array[0..7] of TTeam;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    38
            arguments: array[0..Pred(MAXARGS)] of shortstring;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    39
            argv: array[0..Pred(MAXARGS)] of PChar;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    40
            argumentsNumber: Longword;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    41
            end;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    42
    PGameConfig = ^TGameConfig;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    43
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    44
var currentConfig: TGameConfig;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    45
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    46
procedure queueExecution;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    47
var pConfig: PGameConfig;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    48
    i: Longword;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    49
begin
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    50
    new(pConfig);
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    51
    pConfig^:= currentConfig;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    52
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    53
    with pConfig^ do
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    54
        for i:= 0 to Pred(MAXARGS) do
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    55
        begin
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    56
            if arguments[i][0] = #255 then 
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    57
                arguments[i][255] = #0
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    58
            else
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    59
                arguments[i][byte(arguments[i][0]) + 1] = #0;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    60
            argv[i]:= @arguments[i][1]
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    61
        end;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    62
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    63
    RunEngine(pConfig^.argumentsNumber, @pConfig^.argv);
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    64
end;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    65
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    66
procedure resetGameConfig; cdecl;
10406
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
    67
begin
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
    68
end;
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
    69
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    70
procedure runQuickGame; cdecl; export;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    71
begin
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    72
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    73
end;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    74
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    75
procedure getPreview; cdecl; export;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    76
begin
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    77
    with currentConfig do
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    78
    begin
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    79
        gameType:= gtPreview;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    80
        arguments[0]:= '';
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    81
        arguments[1]:= '--internal';
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    82
        arguments[2]:= '--landpreview';
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    83
        argumentsNumber:= 3;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    84
    end;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    85
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    86
    queueExecution
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    87
end;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    88
10406
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
    89
end.