hedgewars/uFLGameConfig.pas
author unc0rr
Sun, 28 Sep 2014 21:33:14 +0400
branchqmlfrontend
changeset 10432 b0abef0ee78c
parent 10430 899a30018ede
child 10444 47a6231f1fc1
permissions -rw-r--r--
Quick Game PoC
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
interface
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
     3
uses uFLTypes;
10406
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
     4
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
     5
procedure resetGameConfig; cdecl;
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
     6
procedure runQuickGame; cdecl;
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
     7
procedure getPreview; cdecl;
10406
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
     8
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
     9
procedure registerGUIMessagesCallback(p: pointer; f: TGUICallback); cdecl;
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    10
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    11
procedure setSeed(seed: PChar); cdecl;
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    12
function  getSeed: PChar; cdecl;
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
    13
10406
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
    14
implementation
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    15
uses uFLIPC, hwengine, uFLUtils, uFLTeams;
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
    16
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
    17
var guiCallbackPointer: pointer;
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
    18
    guiCallbackFunction: TGUICallback;
10406
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
    19
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    20
const
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    21
    MAXCONFIGS = 5;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    22
    MAXARGS = 32;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    23
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    24
type
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    25
    TGameConfig = record
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    26
            seed: shortstring;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    27
            theme: shortstring;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    28
            script: shortstring;
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    29
            mapgen: Longint;
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    30
            gameType: TGameType;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    31
            teams: array[0..7] of TTeam;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    32
            arguments: array[0..Pred(MAXARGS)] of shortstring;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    33
            argv: array[0..Pred(MAXARGS)] of PChar;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    34
            argumentsNumber: Longword;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    35
            end;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    36
    PGameConfig = ^TGameConfig;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    37
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    38
var
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    39
    currentConfig: TGameConfig;
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    40
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    41
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    42
procedure sendConfig(config: PGameConfig);
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    43
var i: Longword;
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    44
begin
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    45
with config^ do
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    46
begin
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    47
    case gameType of
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    48
    gtPreview: begin
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    49
            ipcToEngine('eseed ' + seed);
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    50
            ipcToEngine('e$mapgen ' + intToStr(mapgen));
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    51
        end;
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    52
    gtLocal: begin
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    53
            ipcToEngine('eseed ' + seed);
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    54
            ipcToEngine('e$mapgen ' + intToStr(mapgen));
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    55
            i:= 0;
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    56
            while (i < 8) and (teams[i].hogsNumber > 0) do
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    57
                begin
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    58
                    ipcToEngine('eammloadt 93919294221991210322351110012000000002111001010111110001');
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    59
                    ipcToEngine('eammprob 04050405416006555465544647765766666661555101011154111111');
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    60
                    ipcToEngine('eammdelay 00000000000002055000000400070040000000002200000006000200');
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    61
                    ipcToEngine('eammreinf 13111103121111111231141111111111111112111111011111111111');
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    62
                    ipcToEngine('eammstore');
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    63
                    sendTeamConfig(teams[i]);
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    64
                    inc(i)
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    65
                end;
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    66
        end;
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    67
    end;
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    68
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    69
    ipcToEngine('!');
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    70
end;
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    71
end;
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    72
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    73
procedure queueExecution;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    74
var pConfig: PGameConfig;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    75
    i: Longword;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    76
begin
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    77
    new(pConfig);
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    78
    pConfig^:= currentConfig;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    79
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    80
    with pConfig^ do
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    81
        for i:= 0 to Pred(MAXARGS) do
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    82
        begin
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    83
            if arguments[i][0] = #255 then 
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
    84
                arguments[i][255]:= #0
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    85
            else
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
    86
                arguments[i][byte(arguments[i][0]) + 1]:= #0;
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    87
            argv[i]:= @arguments[i][1]
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    88
        end;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    89
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    90
    RunEngine(pConfig^.argumentsNumber, @pConfig^.argv);
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    91
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    92
    sendConfig(pConfig)
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    93
end;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    94
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    95
procedure resetGameConfig; cdecl;
10406
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
    96
begin
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
    97
end;
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
    98
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    99
procedure setSeed(seed: PChar); cdecl;
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   100
begin
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   101
    currentConfig.seed:= seed
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   102
end;
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   103
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   104
function getSeed: PChar; cdecl;
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   105
begin
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   106
    getSeed:= str2PChar(currentConfig.seed)
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   107
end;
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   108
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   109
procedure runQuickGame; cdecl;
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   110
begin
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   111
    with currentConfig do
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   112
    begin
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   113
        gameType:= gtLocal;
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   114
        arguments[0]:= '';
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   115
        arguments[1]:= '--internal';
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   116
        arguments[2]:= '--nosound';
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   117
        argumentsNumber:= 3;
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   118
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   119
        teams[0]:= createRandomTeam;
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   120
        teams[0].color:= '6341088';
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   121
        teams[1]:= createRandomTeam;
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   122
        teams[1].color:= '2113696';
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   123
        teams[1].botLevel:= 1;
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   124
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   125
        queueExecution;
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   126
    end;
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   127
end;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   128
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   129
procedure getPreview; cdecl;
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   130
begin
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   131
    with currentConfig do
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   132
    begin
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   133
        gameType:= gtPreview;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   134
        arguments[0]:= '';
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   135
        arguments[1]:= '--internal';
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   136
        arguments[2]:= '--landpreview';
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   137
        argumentsNumber:= 3;
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   138
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   139
        queueExecution;
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   140
    end;
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   141
end;
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   142
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   143
procedure engineMessageCallback(p: pointer; msg: PChar; len: Longword);
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   144
begin
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   145
    if len = 128 * 256 then guiCallbackFunction(guiCallbackPointer, mtPreview, msg, len)
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   146
end;
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   147
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   148
procedure registerGUIMessagesCallback(p: pointer; f: TGUICallback); cdecl;
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   149
begin
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   150
    guiCallbackPointer:= p;
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   151
    guiCallbackFunction:= f;
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   152
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   153
    registerIPCCallback(nil, @engineMessageCallback)
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   154
end;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   155
10406
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
   156
end.