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