hedgewars/uFLGameConfig.pas
author unc0rr
Tue, 15 Mar 2016 22:29:40 +0300
branchqmlfrontend
changeset 11607 f0dcdbb9b2fe
parent 11480 b0c34402038c
permissions -rw-r--r--
logging via physfs
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 setSeed(seed: PChar); cdecl;
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    11
function  getSeed: PChar; cdecl;
10456
6fd99bb73524 Theme can be changed
unc0rr
parents: 10452
diff changeset
    12
procedure setTheme(themeName: PChar); cdecl;
10612
eb3c1a289a23 Script combobox.wiki
unc0rr
parents: 10456
diff changeset
    13
procedure setScript(scriptName: PChar); cdecl;
10819
57e21f7621b0 Send selected scheme config on engine initialization (WIP)
unc0rr
parents: 10612
diff changeset
    14
procedure setScheme(schemeName: PChar); cdecl;
10888
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
    15
procedure setAmmo(ammoName: PChar); cdecl;
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
    16
10452
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
    17
procedure tryAddTeam(teamName: PChar); cdecl;
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
    18
procedure tryRemoveTeam(teamName: PChar); cdecl;
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
    19
procedure changeTeamColor(teamName: PChar; dir: LongInt); cdecl;
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
    20
11431
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11424
diff changeset
    21
procedure netSetSeed(seed: shortstring);
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11424
diff changeset
    22
procedure netSetTheme(themeName: shortstring);
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11424
diff changeset
    23
procedure netSetScript(scriptName: shortstring);
11433
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
    24
procedure netSetFeatureSize(fsize: LongInt);
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
    25
procedure netSetMapGen(mapgen: LongInt);
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
    26
procedure netSetMap(map: shortstring);
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
    27
procedure netSetMazeSize(mazesize: LongInt);
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
    28
procedure netSetTemplate(template: LongInt);
11437
6e641b5453f9 Accept ammo scheme from network
unc0rr
parents: 11434
diff changeset
    29
procedure netSetAmmo(name: shortstring; definition: ansistring);
11440
330c14f4ba69 Accept scheme from net
unc0rr
parents: 11438
diff changeset
    30
procedure netSetScheme(scheme: TScheme);
11442
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
    31
procedure netAddTeam(team: TTeam);
11444
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
    32
procedure netAcceptedTeam(teamName: shortstring);
11442
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
    33
procedure netSetTeamColor(team: shortstring; color: Longword);
11443
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
    34
procedure netSetHedgehogsNumber(team: shortstring; hogsNumber: Longword);
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
    35
procedure netRemoveTeam(teamName: shortstring);
11462
33a0e3a14ddc - Fix passing of ansistrings via ipc
unc0rr
parents: 11458
diff changeset
    36
procedure netDrawnData(data: ansistring);
11443
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
    37
procedure netResetTeams();
11433
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
    38
procedure updatePreviewIfNeeded;
11431
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11424
diff changeset
    39
11434
23912c93935a - Implement engine runs queue
unc0rr
parents: 11433
diff changeset
    40
procedure sendConfig(config: PGameConfig);
11451
6e9b12864856 Start work on running engine in network game
unc0rr
parents: 11450
diff changeset
    41
procedure runNetGame();
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    42
11434
23912c93935a - Implement engine runs queue
unc0rr
parents: 11433
diff changeset
    43
implementation
11462
33a0e3a14ddc - Fix passing of ansistrings via ipc
unc0rr
parents: 11458
diff changeset
    44
uses uFLIPC, uFLUtils, uFLTeams, uFLThemes, uFLSChemes, uFLAmmo
11480
b0c34402038c Handle drawn maps from net
unc0rr
parents: 11462
diff changeset
    45
    , uFLUICallback, uFLRunQueue, uFLNet, uUtils, uFLDrawnMap
b0c34402038c Handle drawn maps from net
unc0rr
parents: 11462
diff changeset
    46
    , SDLh;
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    47
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    48
var
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    49
    currentConfig: TGameConfig;
11433
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
    50
    previewNeedsUpdate: boolean;
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    51
11431
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11424
diff changeset
    52
function getScriptPath(scriptName: shortstring): shortstring;
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11424
diff changeset
    53
begin
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11424
diff changeset
    54
    getScriptPath:= '/Scripts/Multiplayer/' + scriptName + '.lua'
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11424
diff changeset
    55
end;
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    56
11462
33a0e3a14ddc - Fix passing of ansistrings via ipc
unc0rr
parents: 11458
diff changeset
    57
procedure sendDrawnMap(config: PGameConfig);
33a0e3a14ddc - Fix passing of ansistrings via ipc
unc0rr
parents: 11458
diff changeset
    58
var i: Longword;
11480
b0c34402038c Handle drawn maps from net
unc0rr
parents: 11462
diff changeset
    59
    data: PByteArray;
b0c34402038c Handle drawn maps from net
unc0rr
parents: 11462
diff changeset
    60
    dataLen: Longword;
11462
33a0e3a14ddc - Fix passing of ansistrings via ipc
unc0rr
parents: 11458
diff changeset
    61
    s: shortstring;
33a0e3a14ddc - Fix passing of ansistrings via ipc
unc0rr
parents: 11458
diff changeset
    62
begin
11480
b0c34402038c Handle drawn maps from net
unc0rr
parents: 11462
diff changeset
    63
    decodeDrawnMap(config^.drawnData, config^.drawnDataSize, data, dataLen);
11462
33a0e3a14ddc - Fix passing of ansistrings via ipc
unc0rr
parents: 11458
diff changeset
    64
11480
b0c34402038c Handle drawn maps from net
unc0rr
parents: 11462
diff changeset
    65
    i:= 0;
b0c34402038c Handle drawn maps from net
unc0rr
parents: 11462
diff changeset
    66
b0c34402038c Handle drawn maps from net
unc0rr
parents: 11462
diff changeset
    67
    s[0]:= #240;
b0c34402038c Handle drawn maps from net
unc0rr
parents: 11462
diff changeset
    68
    while i < dataLen do
11462
33a0e3a14ddc - Fix passing of ansistrings via ipc
unc0rr
parents: 11458
diff changeset
    69
    begin
11480
b0c34402038c Handle drawn maps from net
unc0rr
parents: 11462
diff changeset
    70
        if dataLen - i > 240 then
b0c34402038c Handle drawn maps from net
unc0rr
parents: 11462
diff changeset
    71
        begin
b0c34402038c Handle drawn maps from net
unc0rr
parents: 11462
diff changeset
    72
            Move(data^[i], s[1], 240)
b0c34402038c Handle drawn maps from net
unc0rr
parents: 11462
diff changeset
    73
        end else
b0c34402038c Handle drawn maps from net
unc0rr
parents: 11462
diff changeset
    74
        begin
b0c34402038c Handle drawn maps from net
unc0rr
parents: 11462
diff changeset
    75
            Move(data^[i], s[1], dataLen - i);
b0c34402038c Handle drawn maps from net
unc0rr
parents: 11462
diff changeset
    76
            s[0]:= char(dataLen - i)
b0c34402038c Handle drawn maps from net
unc0rr
parents: 11462
diff changeset
    77
        end;
b0c34402038c Handle drawn maps from net
unc0rr
parents: 11462
diff changeset
    78
b0c34402038c Handle drawn maps from net
unc0rr
parents: 11462
diff changeset
    79
        ipcToEngine('edraw ' + s);
11462
33a0e3a14ddc - Fix passing of ansistrings via ipc
unc0rr
parents: 11458
diff changeset
    80
        inc(i, 240)
33a0e3a14ddc - Fix passing of ansistrings via ipc
unc0rr
parents: 11458
diff changeset
    81
    end;
11480
b0c34402038c Handle drawn maps from net
unc0rr
parents: 11462
diff changeset
    82
b0c34402038c Handle drawn maps from net
unc0rr
parents: 11462
diff changeset
    83
    if dataLen > 0 then
b0c34402038c Handle drawn maps from net
unc0rr
parents: 11462
diff changeset
    84
        FreeMem(data, dataLen);
11462
33a0e3a14ddc - Fix passing of ansistrings via ipc
unc0rr
parents: 11458
diff changeset
    85
end;
33a0e3a14ddc - Fix passing of ansistrings via ipc
unc0rr
parents: 11458
diff changeset
    86
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    87
procedure sendConfig(config: PGameConfig);
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    88
var i: Longword;
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    89
begin
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    90
with config^ do
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    91
begin
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    92
    case gameType of
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    93
    gtPreview: begin
11431
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11424
diff changeset
    94
            if script <> 'Normal' then
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11424
diff changeset
    95
                ipcToEngine('escript ' + getScriptPath(script));
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    96
            ipcToEngine('eseed ' + seed);
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    97
            ipcToEngine('e$mapgen ' + intToStr(mapgen));
11447
2572afe532af Don't send maze_size parameter when not needed, as it overwrites template_filter
unc0rr
parents: 11446
diff changeset
    98
            if (mapgen = 1) or (mapgen = 2) then
11450
0c75fa9ce340 - Use queues instead of single buffer to communicate between threads
unc0rr
parents: 11447
diff changeset
    99
                ipcToEngine('e$maze_size ' + intToStr(mazeSize))
11447
2572afe532af Don't send maze_size parameter when not needed, as it overwrites template_filter
unc0rr
parents: 11446
diff changeset
   100
            else
2572afe532af Don't send maze_size parameter when not needed, as it overwrites template_filter
unc0rr
parents: 11446
diff changeset
   101
                ipcToEngine('e$template_filter ' + intToStr(template));
11434
23912c93935a - Implement engine runs queue
unc0rr
parents: 11433
diff changeset
   102
            ipcToEngine('e$feature_size ' + intToStr(featureSize));
11462
33a0e3a14ddc - Fix passing of ansistrings via ipc
unc0rr
parents: 11458
diff changeset
   103
            if mapgen = 3 then
33a0e3a14ddc - Fix passing of ansistrings via ipc
unc0rr
parents: 11458
diff changeset
   104
                sendDrawnMap(config);
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   105
        end;
11454
3c5d99013baf - Improve IPC handling in engine
unc0rr
parents: 11453
diff changeset
   106
gtLocal, gtNet: begin
3c5d99013baf - Improve IPC handling in engine
unc0rr
parents: 11453
diff changeset
   107
            if gameType = gtNet then
3c5d99013baf - Improve IPC handling in engine
unc0rr
parents: 11453
diff changeset
   108
                ipcToEngine('TN');
11431
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11424
diff changeset
   109
            if script <> 'Normal' then
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11424
diff changeset
   110
                ipcToEngine('escript ' + getScriptPath(script));
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   111
            ipcToEngine('eseed ' + seed);
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   112
            ipcToEngine('e$mapgen ' + intToStr(mapgen));
11447
2572afe532af Don't send maze_size parameter when not needed, as it overwrites template_filter
unc0rr
parents: 11446
diff changeset
   113
            if (mapgen = 1) or (mapgen = 2) then
11450
0c75fa9ce340 - Use queues instead of single buffer to communicate between threads
unc0rr
parents: 11447
diff changeset
   114
                ipcToEngine('e$maze_size ' + intToStr(mazeSize))
11447
2572afe532af Don't send maze_size parameter when not needed, as it overwrites template_filter
unc0rr
parents: 11446
diff changeset
   115
            else
2572afe532af Don't send maze_size parameter when not needed, as it overwrites template_filter
unc0rr
parents: 11446
diff changeset
   116
                ipcToEngine('e$template_filter ' + intToStr(template));
11434
23912c93935a - Implement engine runs queue
unc0rr
parents: 11433
diff changeset
   117
            ipcToEngine('e$feature_size ' + intToStr(featureSize));
10456
6fd99bb73524 Theme can be changed
unc0rr
parents: 10452
diff changeset
   118
            ipcToEngine('e$theme ' + theme);
11462
33a0e3a14ddc - Fix passing of ansistrings via ipc
unc0rr
parents: 11458
diff changeset
   119
            if mapgen = 3 then
33a0e3a14ddc - Fix passing of ansistrings via ipc
unc0rr
parents: 11458
diff changeset
   120
                sendDrawnMap(config);
10612
eb3c1a289a23 Script combobox.wiki
unc0rr
parents: 10456
diff changeset
   121
10819
57e21f7621b0 Send selected scheme config on engine initialization (WIP)
unc0rr
parents: 10612
diff changeset
   122
            sendSchemeConfig(scheme);
57e21f7621b0 Send selected scheme config on engine initialization (WIP)
unc0rr
parents: 10612
diff changeset
   123
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   124
            i:= 0;
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   125
            while (i < 8) and (teams[i].hogsNumber > 0) do
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   126
                begin
11458
8318e841648f Send full game config to the engine
unc0rr
parents: 11454
diff changeset
   127
                    sendTeamConfig(config^.scheme.health, teams[i]);
10892
83a99e2f8b00 Make ammo scheme work
unc0rr
parents: 10888
diff changeset
   128
                    sendAmmoConfig(config^.ammo);
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   129
                    inc(i)
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   130
                end;
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   131
        end;
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   132
    end;
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   133
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   134
    ipcToEngine('!');
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   135
end;
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   136
end;
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   137
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   138
procedure resetGameConfig; cdecl;
10450
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
   139
var i: Longword;
10406
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
   140
begin
10450
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
   141
    with currentConfig do
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
   142
    begin
11431
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11424
diff changeset
   143
        script:= 'Normal';
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11424
diff changeset
   144
10450
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
   145
        for i:= 0 to 7 do
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
   146
            teams[i].hogsNumber:= 0
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
   147
    end
10406
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
   148
end;
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
   149
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   150
procedure setSeed(seed: PChar); cdecl;
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   151
begin
11431
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11424
diff changeset
   152
    sendUI(mtSeed, @seed[1], length(seed));
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   153
    currentConfig.seed:= seed
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   154
end;
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   155
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   156
function getSeed: PChar; cdecl;
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   157
begin
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   158
    getSeed:= str2PChar(currentConfig.seed)
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   159
end;
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   160
10450
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
   161
function getUnusedColor: Longword;
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   162
var i, c: Longword;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   163
    fColorMatched: boolean;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   164
begin
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   165
    c:= 0;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   166
    i:= 0;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   167
    repeat
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   168
        repeat
10450
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
   169
            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
   170
            inc(i)
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   171
        until (i >= 8) or (currentConfig.teams[i].hogsNumber = 0) or fColorMatched;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   172
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   173
        if fColorMatched then
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   174
        begin
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   175
            i:= 0;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   176
            inc(c)
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   177
        end;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   178
    until not fColorMatched;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   179
10450
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
   180
    getUnusedColor:= c
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   181
end;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   182
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   183
procedure runQuickGame; cdecl;
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   184
begin
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   185
    with currentConfig do
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   186
    begin
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   187
        gameType:= gtLocal;
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   188
        arguments[0]:= '';
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   189
        arguments[1]:= '--internal';
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   190
        arguments[2]:= '--nomusic';
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   191
        argumentsNumber:= 3;
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   192
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   193
        teams[0]:= createRandomTeam;
10450
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
   194
        teams[0].color:= 0;
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   195
        teams[1]:= createRandomTeam;
10450
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
   196
        teams[1].color:= 1;
11424
86c13e5662f1 - Some refactoring
unc0rr
parents: 10951
diff changeset
   197
        teams[1].botLevel:= 3;
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   198
11434
23912c93935a - Implement engine runs queue
unc0rr
parents: 11433
diff changeset
   199
        queueExecution(currentConfig);
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   200
    end;
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   201
end;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   202
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   203
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   204
procedure getPreview; cdecl;
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   205
begin
11433
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   206
    previewNeedsUpdate:= false;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   207
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   208
    with currentConfig do
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   209
    begin
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   210
        gameType:= gtPreview;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   211
        arguments[0]:= '';
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   212
        arguments[1]:= '--internal';
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   213
        arguments[2]:= '--landpreview';
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   214
        argumentsNumber:= 3;
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   215
11434
23912c93935a - Implement engine runs queue
unc0rr
parents: 11433
diff changeset
   216
        queueExecution(currentConfig);
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   217
    end;
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   218
end;
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   219
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   220
procedure runLocalGame; cdecl;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   221
begin
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   222
    with currentConfig do
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   223
    begin
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   224
        gameType:= gtLocal;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   225
        arguments[0]:= '';
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   226
        arguments[1]:= '--internal';
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   227
        arguments[2]:= '--nomusic';
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   228
        argumentsNumber:= 3;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   229
11434
23912c93935a - Implement engine runs queue
unc0rr
parents: 11433
diff changeset
   230
        queueExecution(currentConfig);
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   231
    end;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   232
end;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   233
11451
6e9b12864856 Start work on running engine in network game
unc0rr
parents: 11450
diff changeset
   234
procedure runNetGame();
6e9b12864856 Start work on running engine in network game
unc0rr
parents: 11450
diff changeset
   235
begin
6e9b12864856 Start work on running engine in network game
unc0rr
parents: 11450
diff changeset
   236
    with currentConfig do
6e9b12864856 Start work on running engine in network game
unc0rr
parents: 11450
diff changeset
   237
    begin
6e9b12864856 Start work on running engine in network game
unc0rr
parents: 11450
diff changeset
   238
        gameType:= gtNet;
6e9b12864856 Start work on running engine in network game
unc0rr
parents: 11450
diff changeset
   239
        arguments[0]:= '';
6e9b12864856 Start work on running engine in network game
unc0rr
parents: 11450
diff changeset
   240
        arguments[1]:= '--internal';
6e9b12864856 Start work on running engine in network game
unc0rr
parents: 11450
diff changeset
   241
        arguments[2]:= '--nomusic';
6e9b12864856 Start work on running engine in network game
unc0rr
parents: 11450
diff changeset
   242
        argumentsNumber:= 3;
6e9b12864856 Start work on running engine in network game
unc0rr
parents: 11450
diff changeset
   243
6e9b12864856 Start work on running engine in network game
unc0rr
parents: 11450
diff changeset
   244
        queueExecution(currentConfig);
6e9b12864856 Start work on running engine in network game
unc0rr
parents: 11450
diff changeset
   245
    end;
6e9b12864856 Start work on running engine in network game
unc0rr
parents: 11450
diff changeset
   246
end;
6e9b12864856 Start work on running engine in network game
unc0rr
parents: 11450
diff changeset
   247
10452
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   248
procedure tryAddTeam(teamName: PChar); cdecl;
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
   249
var msg: ansistring;
10446
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   250
    i, hn, hedgehogsNumber: Longword;
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   251
    team: PTeam;
10450
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
   252
    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
   253
begin
11444
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   254
    team:= teamByName(teamName);
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   255
    if team = nil then exit;
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   256
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   257
    if isConnected then
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   258
        sendTeam(team^)
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   259
    else
10446
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   260
    with currentConfig do
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   261
    begin
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   262
        hedgehogsNumber:= 0;
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   263
        i:= 0;
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   264
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   265
        while (i < 8) and (teams[i].hogsNumber > 0) do
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   266
        begin
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   267
            inc(i);
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   268
            inc(hedgehogsNumber, teams[i].hogsNumber)
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   269
        end;
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   270
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   271
        // no free space for a team or reached hogs number maximum
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   272
        if (i > 7) or (hedgehogsNumber >= 48) then exit;
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   273
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   274
        c:= getUnusedColor;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   275
10446
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   276
        teams[i]:= team^;
11454
3c5d99013baf - Improve IPC handling in engine
unc0rr
parents: 11453
diff changeset
   277
        teams[i].extDriven:= false;
10446
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   278
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   279
        if i = 0 then hn:= 4 else hn:= teams[i - 1].hogsNumber;
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   280
        if hn > 48 - hedgehogsNumber then hn:= 48 - hedgehogsNumber;
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   281
        teams[i].hogsNumber:= hn;
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   282
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   283
        teams[i].color:= c;
10446
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   284
10452
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   285
        msg:= '0' + #10 + teamName;
10951
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents: 10892
diff changeset
   286
        sendUI(mtAddPlayingTeam, @msg[1], length(msg));
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
   287
10452
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   288
        msg:= teamName + #10 + colorsSet[teams[i].color];
10951
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents: 10892
diff changeset
   289
        sendUI(mtTeamColor, @msg[1], length(msg));
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
   290
11443
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   291
        msg:= teamName + #10 + IntToStr(hn);
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   292
        sendUI(mtHedgehogsNumber, @msg[1], length(msg));
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   293
10452
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   294
        msg:= teamName;
10951
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents: 10892
diff changeset
   295
        sendUI(mtRemoveTeam, @msg[1], length(msg))
10452
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   296
    end
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
   297
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
   298
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   299
10452
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   300
procedure tryRemoveTeam(teamName: PChar); cdecl;
11446
321d0ce43568 Send team removal message to net
unc0rr
parents: 11444
diff changeset
   301
var i: Longword;
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   302
    tn: shortstring;
11446
321d0ce43568 Send team removal message to net
unc0rr
parents: 11444
diff changeset
   303
    isLocal: boolean;
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
   304
begin
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   305
    with currentConfig do
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   306
    begin
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   307
        i:= 0;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   308
        tn:= teamName;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   309
        while (i < 8) and (teams[i].teamName <> tn) do
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   310
            inc(i);
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   311
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   312
        // team not found???
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   313
        if (i > 7) then exit;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   314
11446
321d0ce43568 Send team removal message to net
unc0rr
parents: 11444
diff changeset
   315
        isLocal:= not teams[i].extDriven;
321d0ce43568 Send team removal message to net
unc0rr
parents: 11444
diff changeset
   316
321d0ce43568 Send team removal message to net
unc0rr
parents: 11444
diff changeset
   317
        if isConnected and not isLocal then
321d0ce43568 Send team removal message to net
unc0rr
parents: 11444
diff changeset
   318
            exit; // we cannot remove this team
321d0ce43568 Send team removal message to net
unc0rr
parents: 11444
diff changeset
   319
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   320
        while (i < 7) and (teams[i + 1].hogsNumber > 0) do
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   321
        begin
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   322
            teams[i]:= teams[i + 1];
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   323
            inc(i)
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   324
        end;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   325
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   326
        teams[i].hogsNumber:= 0
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   327
    end;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   328
11446
321d0ce43568 Send team removal message to net
unc0rr
parents: 11444
diff changeset
   329
    sendUI(mtRemovePlayingTeam, @tn[1], length(tn));
321d0ce43568 Send team removal message to net
unc0rr
parents: 11444
diff changeset
   330
    if isConnected then
321d0ce43568 Send team removal message to net
unc0rr
parents: 11444
diff changeset
   331
        removeTeam(tn);
321d0ce43568 Send team removal message to net
unc0rr
parents: 11444
diff changeset
   332
    if isLocal then
321d0ce43568 Send team removal message to net
unc0rr
parents: 11444
diff changeset
   333
        sendUI(mtAddTeam, @tn[1], length(tn))
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
   334
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
   335
10452
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   336
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   337
procedure changeTeamColor(teamName: PChar; dir: LongInt); cdecl;
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   338
var i, dc: Longword;
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   339
    tn: shortstring;
11443
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   340
    msg: ansistring;
10452
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   341
begin
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   342
    with currentConfig do
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   343
    begin
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   344
        i:= 0;
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   345
        tn:= teamName;
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   346
        while (i < 8) and (teams[i].teamName <> tn) do
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   347
            inc(i);
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   348
        // team not found???
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   349
        if (i > 7) then exit;
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   350
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   351
        if dir >= 0 then dc:= 1 else dc:= 8;
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   352
        teams[i].color:= (teams[i].color + dc) mod 9;
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   353
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   354
        msg:= tn + #10 + colorsSet[teams[i].color];
10951
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents: 10892
diff changeset
   355
        sendUI(mtTeamColor, @msg[1], length(msg))
10452
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   356
    end
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   357
end;
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   358
10456
6fd99bb73524 Theme can be changed
unc0rr
parents: 10452
diff changeset
   359
procedure setTheme(themeName: PChar); cdecl;
6fd99bb73524 Theme can be changed
unc0rr
parents: 10452
diff changeset
   360
begin
6fd99bb73524 Theme can be changed
unc0rr
parents: 10452
diff changeset
   361
    currentConfig.theme:= themeName
6fd99bb73524 Theme can be changed
unc0rr
parents: 10452
diff changeset
   362
end;
6fd99bb73524 Theme can be changed
unc0rr
parents: 10452
diff changeset
   363
10612
eb3c1a289a23 Script combobox.wiki
unc0rr
parents: 10456
diff changeset
   364
procedure setScript(scriptName: PChar); cdecl;
eb3c1a289a23 Script combobox.wiki
unc0rr
parents: 10456
diff changeset
   365
begin
11431
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11424
diff changeset
   366
    currentConfig.script:= scriptName
10612
eb3c1a289a23 Script combobox.wiki
unc0rr
parents: 10456
diff changeset
   367
end;
eb3c1a289a23 Script combobox.wiki
unc0rr
parents: 10456
diff changeset
   368
10819
57e21f7621b0 Send selected scheme config on engine initialization (WIP)
unc0rr
parents: 10612
diff changeset
   369
procedure setScheme(schemeName: PChar); cdecl;
57e21f7621b0 Send selected scheme config on engine initialization (WIP)
unc0rr
parents: 10612
diff changeset
   370
var scheme: PScheme;
57e21f7621b0 Send selected scheme config on engine initialization (WIP)
unc0rr
parents: 10612
diff changeset
   371
begin
57e21f7621b0 Send selected scheme config on engine initialization (WIP)
unc0rr
parents: 10612
diff changeset
   372
    scheme:= schemeByName(schemeName);
57e21f7621b0 Send selected scheme config on engine initialization (WIP)
unc0rr
parents: 10612
diff changeset
   373
57e21f7621b0 Send selected scheme config on engine initialization (WIP)
unc0rr
parents: 10612
diff changeset
   374
    if scheme <> nil then
57e21f7621b0 Send selected scheme config on engine initialization (WIP)
unc0rr
parents: 10612
diff changeset
   375
        currentConfig.scheme:= scheme^
57e21f7621b0 Send selected scheme config on engine initialization (WIP)
unc0rr
parents: 10612
diff changeset
   376
end;
57e21f7621b0 Send selected scheme config on engine initialization (WIP)
unc0rr
parents: 10612
diff changeset
   377
10888
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
   378
procedure setAmmo(ammoName: PChar); cdecl;
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
   379
var ammo: PAmmo;
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
   380
begin
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
   381
    ammo:= ammoByName(ammoName);
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
   382
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
   383
    if ammo <> nil then
10892
83a99e2f8b00 Make ammo scheme work
unc0rr
parents: 10888
diff changeset
   384
        currentConfig.ammo:= ammo^
10888
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
   385
end;
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
   386
11431
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11424
diff changeset
   387
procedure netSetSeed(seed: shortstring);
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11424
diff changeset
   388
begin
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11424
diff changeset
   389
    if seed <> currentConfig.seed then
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11424
diff changeset
   390
    begin
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11424
diff changeset
   391
        currentConfig.seed:= seed;
11432
97e3e62ea5f9 Update seed, theme and script from net in UI
unc0rr
parents: 11431
diff changeset
   392
        sendUI(mtSeed, @seed[1], length(seed));
97e3e62ea5f9 Update seed, theme and script from net in UI
unc0rr
parents: 11431
diff changeset
   393
97e3e62ea5f9 Update seed, theme and script from net in UI
unc0rr
parents: 11431
diff changeset
   394
        getPreview()
11431
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11424
diff changeset
   395
    end
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11424
diff changeset
   396
end;
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11424
diff changeset
   397
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11424
diff changeset
   398
procedure netSetTheme(themeName: shortstring);
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11424
diff changeset
   399
begin
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11424
diff changeset
   400
    if themeName <> currentConfig.theme then
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11424
diff changeset
   401
    begin
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11424
diff changeset
   402
        currentConfig.theme:= themeName;
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11424
diff changeset
   403
        sendUI(mtTheme, @themeName[1], length(themeName))
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11424
diff changeset
   404
    end
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11424
diff changeset
   405
end;
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11424
diff changeset
   406
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11424
diff changeset
   407
procedure netSetScript(scriptName: shortstring);
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11424
diff changeset
   408
begin
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11424
diff changeset
   409
    if scriptName <> currentConfig.script then
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11424
diff changeset
   410
    begin
11433
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   411
        previewNeedsUpdate:= true;
11431
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11424
diff changeset
   412
        currentConfig.script:= scriptName;
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11424
diff changeset
   413
        sendUI(mtScript, @scriptName[1], length(scriptName))
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11424
diff changeset
   414
    end
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11424
diff changeset
   415
end;
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11424
diff changeset
   416
11433
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   417
procedure netSetFeatureSize(fsize: LongInt);
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   418
var s: shortstring;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   419
begin
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   420
    if fsize <> currentConfig.featureSize then
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   421
    begin
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   422
        previewNeedsUpdate:= true;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   423
        currentConfig.featureSize:= fsize;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   424
        s:= IntToStr(fsize);
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   425
        sendUI(mtFeatureSize, @s[1], length(s))
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   426
    end
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   427
end;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   428
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   429
procedure netSetMapGen(mapgen: LongInt);
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   430
var s: shortstring;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   431
begin
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   432
    if mapgen <> currentConfig.mapgen then
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   433
    begin
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   434
        previewNeedsUpdate:= true;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   435
        currentConfig.mapgen:= mapgen;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   436
        s:= IntToStr(mapgen);
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   437
        sendUI(mtMapGen, @s[1], length(s))
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   438
    end
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   439
end;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   440
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   441
procedure netSetMap(map: shortstring);
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   442
begin
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   443
    sendUI(mtMap, @map[1], length(map))
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   444
end;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   445
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   446
procedure netSetMazeSize(mazesize: LongInt);
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   447
var s: shortstring;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   448
begin
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   449
    if mazesize <> currentConfig.mazesize then
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   450
    begin
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   451
        previewNeedsUpdate:= true;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   452
        currentConfig.mazesize:= mazesize;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   453
        s:= IntToStr(mazesize);
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   454
        sendUI(mtMazeSize, @s[1], length(s))
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   455
    end
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   456
end;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   457
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   458
procedure netSetTemplate(template: LongInt);
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   459
var s: shortstring;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   460
begin
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   461
    if template <> currentConfig.template then
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   462
    begin
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   463
        previewNeedsUpdate:= true;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   464
        currentConfig.template:= template;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   465
        s:= IntToStr(template);
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   466
        sendUI(mtTemplate, @s[1], length(s))
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   467
    end
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   468
end;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   469
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   470
procedure updatePreviewIfNeeded;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   471
begin
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   472
    if previewNeedsUpdate then
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   473
        getPreview
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   474
end;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11432
diff changeset
   475
11437
6e641b5453f9 Accept ammo scheme from network
unc0rr
parents: 11434
diff changeset
   476
procedure netSetAmmo(name: shortstring; definition: ansistring);
6e641b5453f9 Accept ammo scheme from network
unc0rr
parents: 11434
diff changeset
   477
var ammo: TAmmo;
6e641b5453f9 Accept ammo scheme from network
unc0rr
parents: 11434
diff changeset
   478
    i: LongInt;
6e641b5453f9 Accept ammo scheme from network
unc0rr
parents: 11434
diff changeset
   479
begin
6e641b5453f9 Accept ammo scheme from network
unc0rr
parents: 11434
diff changeset
   480
    ammo.ammoName:= name;
6e641b5453f9 Accept ammo scheme from network
unc0rr
parents: 11434
diff changeset
   481
    i:= length(definition) div 4;
6e641b5453f9 Accept ammo scheme from network
unc0rr
parents: 11434
diff changeset
   482
    ammo.a:= copy(definition, 1, i);
6e641b5453f9 Accept ammo scheme from network
unc0rr
parents: 11434
diff changeset
   483
    ammo.b:= copy(definition, i + 1, i);
6e641b5453f9 Accept ammo scheme from network
unc0rr
parents: 11434
diff changeset
   484
    ammo.c:= copy(definition, i * 2 + 1, i);
6e641b5453f9 Accept ammo scheme from network
unc0rr
parents: 11434
diff changeset
   485
    ammo.d:= copy(definition, i * 3 + 1, i);
6e641b5453f9 Accept ammo scheme from network
unc0rr
parents: 11434
diff changeset
   486
6e641b5453f9 Accept ammo scheme from network
unc0rr
parents: 11434
diff changeset
   487
    currentConfig.ammo:= ammo;
6e641b5453f9 Accept ammo scheme from network
unc0rr
parents: 11434
diff changeset
   488
    sendUI(mtAmmo, @name[1], length(name))
6e641b5453f9 Accept ammo scheme from network
unc0rr
parents: 11434
diff changeset
   489
end;
6e641b5453f9 Accept ammo scheme from network
unc0rr
parents: 11434
diff changeset
   490
11440
330c14f4ba69 Accept scheme from net
unc0rr
parents: 11438
diff changeset
   491
procedure netSetScheme(scheme: TScheme);
330c14f4ba69 Accept scheme from net
unc0rr
parents: 11438
diff changeset
   492
begin
330c14f4ba69 Accept scheme from net
unc0rr
parents: 11438
diff changeset
   493
    currentConfig.scheme:= scheme;
330c14f4ba69 Accept scheme from net
unc0rr
parents: 11438
diff changeset
   494
    sendUI(mtScheme, @scheme.schemeName[1], length(scheme.schemeName))
330c14f4ba69 Accept scheme from net
unc0rr
parents: 11438
diff changeset
   495
end;
330c14f4ba69 Accept scheme from net
unc0rr
parents: 11438
diff changeset
   496
11442
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   497
procedure netAddTeam(team: TTeam);
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   498
var msg: ansistring;
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   499
    i, hn, hedgehogsNumber: Longword;
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   500
    c: Longword;
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   501
begin
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   502
    with currentConfig do
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   503
    begin
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   504
        hedgehogsNumber:= 0;
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   505
        i:= 0;
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   506
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   507
        while (i < 8) and (teams[i].hogsNumber > 0) do
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   508
        begin
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   509
            inc(i);
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   510
            inc(hedgehogsNumber, teams[i].hogsNumber)
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   511
        end;
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   512
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   513
        // no free space for a team - server bug???
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   514
        if (i > 7) or (hedgehogsNumber >= 48) then exit;
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   515
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   516
        c:= getUnusedColor;
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   517
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   518
        teams[i]:= team;
11444
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   519
        teams[i].extDriven:= true;
11442
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   520
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   521
        if i = 0 then hn:= 4 else hn:= teams[i - 1].hogsNumber;
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   522
        if hn > 48 - hedgehogsNumber then hn:= 48 - hedgehogsNumber;
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   523
        teams[i].hogsNumber:= hn;
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   524
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   525
        teams[i].color:= c;
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   526
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   527
        msg:= '0' + #10 + team.teamName;
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   528
        sendUI(mtAddPlayingTeam, @msg[1], length(msg));
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   529
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   530
        msg:= team.teamName + #10 + colorsSet[teams[i].color];
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   531
        sendUI(mtTeamColor, @msg[1], length(msg));
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   532
    end
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   533
end;
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   534
11444
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   535
procedure netAcceptedTeam(teamName: shortstring);
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   536
var msg: ansistring;
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   537
    i, hn, hedgehogsNumber: Longword;
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   538
    c: Longword;
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   539
    team: PTeam;
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   540
begin
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   541
    with currentConfig do
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   542
    begin
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   543
        team:= teamByName(teamName);
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   544
        // no such team???
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   545
        if team = nil then exit;
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   546
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   547
        hedgehogsNumber:= 0;
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   548
        i:= 0;
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   549
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   550
        while (i < 8) and (teams[i].hogsNumber > 0) do
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   551
        begin
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   552
            inc(i);
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   553
            inc(hedgehogsNumber, teams[i].hogsNumber)
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   554
        end;
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   555
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   556
        // no free space for a team - server bug???
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   557
        if (i > 7) or (hedgehogsNumber >= 48) then exit;
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   558
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   559
        c:= getUnusedColor;
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   560
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   561
        teams[i]:= team^;
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   562
        teams[i].extDriven:= false;
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   563
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   564
        if i = 0 then hn:= 4 else hn:= teams[i - 1].hogsNumber;
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   565
        if hn > 48 - hedgehogsNumber then hn:= 48 - hedgehogsNumber;
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   566
        teams[i].hogsNumber:= hn;
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   567
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   568
        teams[i].color:= c;
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   569
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   570
        msg:= '0' + #10 + teamName;
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   571
        sendUI(mtAddPlayingTeam, @msg[1], length(msg));
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   572
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   573
        msg:= teamName + #10 + colorsSet[teams[i].color];
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   574
        sendUI(mtTeamColor, @msg[1], length(msg));
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   575
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   576
        msg:= teamName;
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   577
        sendUI(mtRemoveTeam, @msg[1], length(msg))        
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   578
    end
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   579
end;
91f8c6ff5bab - Send team to net
unc0rr
parents: 11443
diff changeset
   580
11443
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   581
procedure netRemoveTeam(teamName: shortstring);
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   582
var msg: shortstring;
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   583
    i: Longword;
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   584
    tn: shortstring;
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   585
    isLocal: boolean;
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   586
begin
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   587
    with currentConfig do
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   588
    begin
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   589
        i:= 0;
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   590
        tn:= teamName;
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   591
        while (i < 8) and (teams[i].teamName <> tn) do
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   592
            inc(i);
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   593
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   594
        // team not found???
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   595
        if (i > 7) then exit;
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   596
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   597
        isLocal:= not teams[i].extDriven;
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   598
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   599
        while (i < 7) and (teams[i + 1].hogsNumber > 0) do
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   600
        begin
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   601
            teams[i]:= teams[i + 1];
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   602
            inc(i)
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   603
        end;
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   604
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   605
        teams[i].hogsNumber:= 0
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   606
    end;
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   607
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   608
    msg:= teamName;
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   609
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   610
    sendUI(mtRemovePlayingTeam, @msg[1], length(msg));
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   611
    if isLocal then
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   612
        sendUI(mtAddTeam, @msg[1], length(msg))
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   613
end;
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   614
11442
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   615
procedure netSetTeamColor(team: shortstring; color: Longword);
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   616
var i: Longword;
11443
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   617
    msg: ansistring;
11442
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   618
begin
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   619
    with currentConfig do
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   620
    begin
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   621
        i:= 0;
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   622
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   623
        while (i < 8) and (teams[i].teamName <> team) do
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   624
            inc(i);
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   625
        // team not found???
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   626
        if (i > 7) then exit;
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   627
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   628
        teams[i].color:= color mod 9;
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   629
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   630
        msg:= team + #10 + colorsSet[teams[i].color];
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   631
        sendUI(mtTeamColor, @msg[1], length(msg))
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   632
    end
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   633
end;
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11440
diff changeset
   634
11443
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   635
procedure netSetHedgehogsNumber(team: shortstring; hogsNumber: Longword);
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   636
var i: Longword;
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   637
    msg: ansistring;
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   638
begin
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   639
    if hogsNumber > 8 then exit;
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   640
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   641
    with currentConfig do
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   642
    begin
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   643
        i:= 0;
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   644
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   645
        while (i < 8) and (teams[i].teamName <> team) do
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   646
            inc(i);
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   647
        // team not found???
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   648
        if (i > 7) then exit;
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   649
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   650
        teams[i].hogsNumber:= hogsNumber;
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   651
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   652
        msg:= team + #10 + IntToStr(hogsNumber);
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   653
        sendUI(mtHedgehogsNumber, @msg[1], length(msg))
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   654
    end
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   655
end;
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   656
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   657
procedure netResetTeams();
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   658
var msg: shortstring;
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   659
    i: Longword;
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   660
begin
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   661
    with currentConfig do
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   662
    begin
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   663
        i:= 0;
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   664
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   665
        while (i < 8) and (teams[i].hogsNumber > 0) do
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   666
        begin
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   667
            msg:= teams[i].teamName;
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   668
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   669
            sendUI(mtRemovePlayingTeam, @msg[1], length(msg));
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   670
            if not teams[i].extDriven then 
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   671
                sendUI(mtAddTeam, @msg[1], length(msg));
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   672
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   673
            teams[i].hogsNumber:= 0;
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   674
            inc(i)
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   675
        end;
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   676
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   677
    end;
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   678
end;
5182d44fb733 - Hedgehogs number display
unc0rr
parents: 11442
diff changeset
   679
11462
33a0e3a14ddc - Fix passing of ansistrings via ipc
unc0rr
parents: 11458
diff changeset
   680
procedure netDrawnData(data: ansistring);
33a0e3a14ddc - Fix passing of ansistrings via ipc
unc0rr
parents: 11458
diff changeset
   681
begin
33a0e3a14ddc - Fix passing of ansistrings via ipc
unc0rr
parents: 11458
diff changeset
   682
    currentConfig.drawnDataSize:= length(data);
33a0e3a14ddc - Fix passing of ansistrings via ipc
unc0rr
parents: 11458
diff changeset
   683
    currentConfig.drawnData:= data;
33a0e3a14ddc - Fix passing of ansistrings via ipc
unc0rr
parents: 11458
diff changeset
   684
33a0e3a14ddc - Fix passing of ansistrings via ipc
unc0rr
parents: 11458
diff changeset
   685
    getPreview
33a0e3a14ddc - Fix passing of ansistrings via ipc
unc0rr
parents: 11458
diff changeset
   686
end;
33a0e3a14ddc - Fix passing of ansistrings via ipc
unc0rr
parents: 11458
diff changeset
   687
10406
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
   688
end.