hedgewars/uFLGameConfig.pas
author unc0rr
Sat, 01 Nov 2014 22:51:07 +0300
branchqmlfrontend
changeset 10450 bf9e30b4ef9b
parent 10448 4cb727e029fa
child 10452 03519fd9f98d
permissions -rw-r--r--
- Store index of color instead of its value - Reset game config when switching pages
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;
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
     7
procedure runLocalGame; cdecl;
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
     8
procedure getPreview; cdecl;
10406
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
     9
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    10
procedure registerGUIMessagesCallback(p: pointer; f: TGUICallback); cdecl;
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    11
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    12
procedure setSeed(seed: PChar); cdecl;
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    13
function  getSeed: PChar; cdecl;
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
    14
10444
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10432
diff changeset
    15
procedure tryAddTeam(teamName: PChar);
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10432
diff changeset
    16
procedure tryRemoveTeam(teamName: PChar);
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10432
diff changeset
    17
10406
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
    18
implementation
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
    19
uses uFLIPC, hwengine, uFLUtils, uFLTeams, uFLData;
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
    20
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
    21
var guiCallbackPointer: pointer;
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
    22
    guiCallbackFunction: TGUICallback;
10406
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
    23
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    24
const
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    25
    MAXCONFIGS = 5;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    26
    MAXARGS = 32;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    27
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    28
type
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    29
    TGameConfig = record
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    30
            seed: shortstring;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    31
            theme: shortstring;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    32
            script: shortstring;
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    33
            mapgen: Longint;
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    34
            gameType: TGameType;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    35
            teams: array[0..7] of TTeam;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    36
            arguments: array[0..Pred(MAXARGS)] of shortstring;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    37
            argv: array[0..Pred(MAXARGS)] of PChar;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    38
            argumentsNumber: Longword;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    39
            end;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    40
    PGameConfig = ^TGameConfig;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    41
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    42
var
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    43
    currentConfig: TGameConfig;
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    44
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    45
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    46
procedure sendConfig(config: PGameConfig);
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    47
var i: Longword;
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    48
begin
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    49
with config^ do
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    50
begin
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    51
    case gameType of
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    52
    gtPreview: 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
        end;
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    56
    gtLocal: begin
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    57
            ipcToEngine('eseed ' + seed);
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    58
            ipcToEngine('e$mapgen ' + intToStr(mapgen));
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    59
            i:= 0;
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    60
            while (i < 8) and (teams[i].hogsNumber > 0) do
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    61
                begin
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    62
                    ipcToEngine('eammloadt 93919294221991210322351110012000000002111001010111110001');
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    63
                    ipcToEngine('eammprob 04050405416006555465544647765766666661555101011154111111');
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    64
                    ipcToEngine('eammdelay 00000000000002055000000400070040000000002200000006000200');
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    65
                    ipcToEngine('eammreinf 13111103121111111231141111111111111112111111011111111111');
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    66
                    ipcToEngine('eammstore');
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    67
                    sendTeamConfig(teams[i]);
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    68
                    inc(i)
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    69
                end;
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    70
        end;
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    71
    end;
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    72
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    73
    ipcToEngine('!');
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    74
end;
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    75
end;
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    76
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    77
procedure queueExecution;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    78
var pConfig: PGameConfig;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    79
    i: Longword;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    80
begin
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    81
    new(pConfig);
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    82
    pConfig^:= currentConfig;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    83
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    84
    with pConfig^ do
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    85
        for i:= 0 to Pred(MAXARGS) do
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    86
        begin
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    87
            if arguments[i][0] = #255 then 
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
    88
                arguments[i][255]:= #0
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    89
            else
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
    90
                arguments[i][byte(arguments[i][0]) + 1]:= #0;
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    91
            argv[i]:= @arguments[i][1]
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    92
        end;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    93
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    94
    RunEngine(pConfig^.argumentsNumber, @pConfig^.argv);
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    95
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    96
    sendConfig(pConfig)
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    97
end;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    98
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    99
procedure resetGameConfig; cdecl;
10450
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
   100
var i: Longword;
10406
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
   101
begin
10450
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
   102
    with currentConfig do
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
   103
    begin
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
   104
        for i:= 0 to 7 do
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
   105
            teams[i].hogsNumber:= 0
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
   106
    end
10406
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
   107
end;
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
   108
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   109
procedure setSeed(seed: PChar); cdecl;
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   110
begin
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   111
    currentConfig.seed:= seed
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   112
end;
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   113
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   114
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   115
function getSeed: PChar; cdecl;
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   116
begin
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   117
    getSeed:= str2PChar(currentConfig.seed)
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   118
end;
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   119
10450
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
   120
function getUnusedColor: Longword;
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   121
var i, c: Longword;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   122
    fColorMatched: boolean;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   123
begin
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   124
    c:= 0;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   125
    i:= 0;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   126
    repeat
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   127
        repeat
10450
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
   128
            fColorMatched:= (currentConfig.teams[i].hogsNumber > 0) and (currentConfig.teams[i].color = c);
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   129
            inc(i)
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   130
        until (i >= 8) or (currentConfig.teams[i].hogsNumber = 0) or fColorMatched;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   131
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   132
        if fColorMatched then
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   133
        begin
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   134
            i:= 0;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   135
            inc(c)
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   136
        end;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   137
    until not fColorMatched;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   138
10450
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
   139
    getUnusedColor:= c
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   140
end;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   141
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   142
procedure runQuickGame; cdecl;
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   143
begin
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   144
    with currentConfig do
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   145
    begin
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   146
        gameType:= gtLocal;
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   147
        arguments[0]:= '';
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   148
        arguments[1]:= '--internal';
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   149
        arguments[2]:= '--nomusic';
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   150
        argumentsNumber:= 3;
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   151
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   152
        teams[0]:= createRandomTeam;
10450
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
   153
        teams[0].color:= 0;
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   154
        teams[1]:= createRandomTeam;
10450
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
   155
        teams[1].color:= 1;
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   156
        teams[1].botLevel:= 1;
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   157
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   158
        queueExecution;
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   159
    end;
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   160
end;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   161
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   162
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   163
procedure getPreview; cdecl;
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   164
begin
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   165
    with currentConfig do
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   166
    begin
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   167
        gameType:= gtPreview;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   168
        arguments[0]:= '';
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   169
        arguments[1]:= '--internal';
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   170
        arguments[2]:= '--landpreview';
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   171
        argumentsNumber:= 3;
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   172
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   173
        queueExecution;
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   174
    end;
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   175
end;
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   176
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   177
procedure runLocalGame; cdecl;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   178
begin
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   179
    with currentConfig do
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   180
    begin
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   181
        gameType:= gtLocal;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   182
        arguments[0]:= '';
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   183
        arguments[1]:= '--internal';
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   184
        arguments[2]:= '--nomusic';
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   185
        argumentsNumber:= 3;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   186
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   187
        queueExecution;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   188
    end;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   189
end;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   190
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   191
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   192
procedure engineMessageCallback(p: pointer; msg: PChar; len: Longword);
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   193
begin
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   194
    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
   195
end;
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   196
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   197
procedure registerGUIMessagesCallback(p: pointer; f: TGUICallback); cdecl;
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   198
begin
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   199
    guiCallbackPointer:= p;
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   200
    guiCallbackFunction:= f;
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   201
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   202
    registerIPCCallback(nil, @engineMessageCallback)
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   203
end;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   204
10444
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10432
diff changeset
   205
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10432
diff changeset
   206
procedure tryAddTeam(teamName: PChar);
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10432
diff changeset
   207
var msg: ansistring;
10446
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   208
    i, hn, hedgehogsNumber: Longword;
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   209
    team: PTeam;
10450
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
   210
    c: Longword;
10444
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10432
diff changeset
   211
begin
10446
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   212
    with currentConfig do
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   213
    begin
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   214
        hedgehogsNumber:= 0;
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   215
        i:= 0;
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   216
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   217
        while (i < 8) and (teams[i].hogsNumber > 0) do
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   218
        begin
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   219
            inc(i);
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   220
            inc(hedgehogsNumber, teams[i].hogsNumber)
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   221
        end;
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   222
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   223
        // no free space for a team or reached hogs number maximum
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   224
        if (i > 7) or (hedgehogsNumber >= 48) then exit;
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   225
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   226
        team:= teamByName(teamName);
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   227
        if team = nil then exit;
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   228
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   229
        c:= getUnusedColor;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   230
10446
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   231
        teams[i]:= team^;
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   232
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   233
        if i = 0 then hn:= 4 else hn:= teams[i - 1].hogsNumber;
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   234
        if hn > 48 - hedgehogsNumber then hn:= 48 - hedgehogsNumber;
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   235
        teams[i].hogsNumber:= hn;
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   236
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   237
        teams[i].color:= c;
10446
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   238
    end;
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   239
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   240
10444
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10432
diff changeset
   241
    msg:= '0' + #10 + teamName;
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10432
diff changeset
   242
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10432
diff changeset
   243
    guiCallbackFunction(guiCallbackPointer, mtAddPlayingTeam, @msg[1], length(msg));
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10432
diff changeset
   244
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10432
diff changeset
   245
    msg:= teamName;
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10432
diff changeset
   246
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10432
diff changeset
   247
    guiCallbackFunction(guiCallbackPointer, mtRemoveTeam, @msg[1], length(msg))
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10432
diff changeset
   248
end;
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10432
diff changeset
   249
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   250
10444
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10432
diff changeset
   251
procedure tryRemoveTeam(teamName: PChar);
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10432
diff changeset
   252
var msg: ansistring;
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   253
    i: Longword;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   254
    tn: shortstring;
10444
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10432
diff changeset
   255
begin
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   256
    with currentConfig do
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   257
    begin
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   258
        i:= 0;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   259
        tn:= teamName;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   260
        while (i < 8) and (teams[i].teamName <> tn) do
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   261
            inc(i);
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   262
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   263
        // team not found???
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   264
        if (i > 7) then exit;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   265
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   266
        while (i < 7) and (teams[i + 1].hogsNumber > 0) do
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   267
        begin
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   268
            teams[i]:= teams[i + 1];
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   269
            inc(i)
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   270
        end;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   271
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   272
        teams[i].hogsNumber:= 0
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   273
    end;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   274
10444
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10432
diff changeset
   275
    msg:= teamName;
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10432
diff changeset
   276
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10432
diff changeset
   277
    guiCallbackFunction(guiCallbackPointer, mtRemovePlayingTeam, @msg[1], length(msg));
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10432
diff changeset
   278
    guiCallbackFunction(guiCallbackPointer, mtAddTeam, @msg[1], length(msg))
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10432
diff changeset
   279
end;
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10432
diff changeset
   280
10406
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
   281
end.