hedgewars/uFLGameConfig.pas
author unc0rr
Thu, 03 Dec 2015 23:59:06 +0300
branchqmlfrontend
changeset 11447 6b04a266feee
parent 11445 330c14f4ba69
child 11448 5182d44fb733
permissions -rw-r--r--
- Accept team and team color from net - Some small fixes
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);
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
    32
procedure netSetTeamColor(team: shortstring; color: Longword);
11438
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
    33
procedure updatePreviewIfNeeded;
11436
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11429
diff changeset
    34
11439
23912c93935a - Implement engine runs queue
unc0rr
parents: 11438
diff changeset
    35
procedure sendConfig(config: PGameConfig);
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    36
11439
23912c93935a - Implement engine runs queue
unc0rr
parents: 11438
diff changeset
    37
implementation
11443
1a6148b4de3b Rename uFLData to uFLThemes
unc0rr
parents: 11442
diff changeset
    38
uses uFLIPC, uFLUtils, uFLTeams, uFLThemes, uFLSChemes, uFLAmmo, uFLUICallback, uFLRunQueue;
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    39
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    40
var
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    41
    currentConfig: TGameConfig;
11438
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
    42
    previewNeedsUpdate: boolean;
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    43
11436
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11429
diff changeset
    44
function getScriptPath(scriptName: shortstring): shortstring;
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11429
diff changeset
    45
begin
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11429
diff changeset
    46
    getScriptPath:= '/Scripts/Multiplayer/' + scriptName + '.lua'
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11429
diff changeset
    47
end;
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    48
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    49
procedure sendConfig(config: PGameConfig);
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    50
var i: Longword;
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    51
begin
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    52
with config^ do
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
    53
begin
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    54
    case gameType of
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    55
    gtPreview: begin
11436
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11429
diff changeset
    56
            if script <> 'Normal' then
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11429
diff changeset
    57
                ipcToEngine('escript ' + getScriptPath(script));
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    58
            ipcToEngine('eseed ' + seed);
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    59
            ipcToEngine('e$mapgen ' + intToStr(mapgen));
11439
23912c93935a - Implement engine runs queue
unc0rr
parents: 11438
diff changeset
    60
            ipcToEngine('e$template_filter ' + intToStr(template));
23912c93935a - Implement engine runs queue
unc0rr
parents: 11438
diff changeset
    61
            ipcToEngine('e$feature_size ' + intToStr(featureSize));
11447
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
    62
            ipcToEngine('e$maze_size ' + intToStr(mazeSize));
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    63
        end;
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    64
    gtLocal: begin
11436
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11429
diff changeset
    65
            if script <> 'Normal' then
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11429
diff changeset
    66
                ipcToEngine('escript ' + getScriptPath(script));
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    67
            ipcToEngine('eseed ' + seed);
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    68
            ipcToEngine('e$mapgen ' + intToStr(mapgen));
11439
23912c93935a - Implement engine runs queue
unc0rr
parents: 11438
diff changeset
    69
            ipcToEngine('e$template_filter ' + intToStr(template));
23912c93935a - Implement engine runs queue
unc0rr
parents: 11438
diff changeset
    70
            ipcToEngine('e$feature_size ' + intToStr(featureSize));
10456
6fd99bb73524 Theme can be changed
unc0rr
parents: 10452
diff changeset
    71
            ipcToEngine('e$theme ' + theme);
11447
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
    72
            ipcToEngine('e$maze_size ' + intToStr(mazeSize));
10612
eb3c1a289a23 Script combobox.wiki
unc0rr
parents: 10456
diff changeset
    73
10819
57e21f7621b0 Send selected scheme config on engine initialization (WIP)
unc0rr
parents: 10612
diff changeset
    74
            sendSchemeConfig(scheme);
57e21f7621b0 Send selected scheme config on engine initialization (WIP)
unc0rr
parents: 10612
diff changeset
    75
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    76
            i:= 0;
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    77
            while (i < 8) and (teams[i].hogsNumber > 0) do
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    78
                begin
11442
6e641b5453f9 Accept ammo scheme from network
unc0rr
parents: 11439
diff changeset
    79
                    sendTeamConfig(teams[i]);
10892
83a99e2f8b00 Make ammo scheme work
unc0rr
parents: 10888
diff changeset
    80
                    sendAmmoConfig(config^.ammo);
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    81
                    inc(i)
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    82
                end;
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    83
        end;
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    84
    end;
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    85
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    86
    ipcToEngine('!');
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    87
end;
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
    88
end;
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    89
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
    90
procedure resetGameConfig; cdecl;
10450
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
    91
var i: Longword;
10406
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
    92
begin
10450
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
    93
    with currentConfig do
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
    94
    begin
11436
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11429
diff changeset
    95
        script:= 'Normal';
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11429
diff changeset
    96
10450
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
    97
        for i:= 0 to 7 do
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
    98
            teams[i].hogsNumber:= 0
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
    99
    end
10406
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
   100
end;
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
   101
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   102
procedure setSeed(seed: PChar); cdecl;
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   103
begin
11436
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11429
diff changeset
   104
    sendUI(mtSeed, @seed[1], length(seed));
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   105
    currentConfig.seed:= seed
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   106
end;
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   107
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   108
function getSeed: PChar; cdecl;
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   109
begin
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   110
    getSeed:= str2PChar(currentConfig.seed)
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   111
end;
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   112
10450
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
   113
function getUnusedColor: Longword;
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   114
var i, c: Longword;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   115
    fColorMatched: boolean;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   116
begin
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   117
    c:= 0;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   118
    i:= 0;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   119
    repeat
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   120
        repeat
10450
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
   121
            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
   122
            inc(i)
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   123
        until (i >= 8) or (currentConfig.teams[i].hogsNumber = 0) or fColorMatched;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   124
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   125
        if fColorMatched then
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   126
        begin
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   127
            i:= 0;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   128
            inc(c)
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   129
        end;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   130
    until not fColorMatched;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   131
10450
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
   132
    getUnusedColor:= c
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   133
end;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   134
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   135
procedure runQuickGame; cdecl;
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   136
begin
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   137
    with currentConfig do
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   138
    begin
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   139
        gameType:= gtLocal;
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   140
        arguments[0]:= '';
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   141
        arguments[1]:= '--internal';
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   142
        arguments[2]:= '--nomusic';
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   143
        argumentsNumber:= 3;
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   144
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   145
        teams[0]:= createRandomTeam;
10450
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
   146
        teams[0].color:= 0;
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   147
        teams[1]:= createRandomTeam;
10450
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
   148
        teams[1].color:= 1;
11429
86c13e5662f1 - Some refactoring
unc0rr
parents: 10951
diff changeset
   149
        teams[1].botLevel:= 3;
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   150
11439
23912c93935a - Implement engine runs queue
unc0rr
parents: 11438
diff changeset
   151
        queueExecution(currentConfig);
10432
b0abef0ee78c Quick Game PoC
unc0rr
parents: 10430
diff changeset
   152
    end;
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   153
end;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   154
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   155
10430
899a30018ede Getter and setter for seed
unc0rr
parents: 10428
diff changeset
   156
procedure getPreview; cdecl;
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   157
begin
11438
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   158
    previewNeedsUpdate:= false;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   159
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   160
    with currentConfig do
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   161
    begin
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   162
        gameType:= gtPreview;
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   163
        arguments[0]:= '';
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   164
        arguments[1]:= '--internal';
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   165
        arguments[2]:= '--landpreview';
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   166
        argumentsNumber:= 3;
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   167
11439
23912c93935a - Implement engine runs queue
unc0rr
parents: 11438
diff changeset
   168
        queueExecution(currentConfig);
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   169
    end;
10428
7c25297720f1 More refactoring: move PoC preview getting code into flib
unc0rr
parents: 10426
diff changeset
   170
end;
10426
727a154cf784 Some refactoring
unc0rr
parents: 10406
diff changeset
   171
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   172
procedure runLocalGame; cdecl;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   173
begin
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   174
    with currentConfig do
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   175
    begin
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   176
        gameType:= gtLocal;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   177
        arguments[0]:= '';
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   178
        arguments[1]:= '--internal';
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   179
        arguments[2]:= '--nomusic';
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   180
        argumentsNumber:= 3;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   181
11439
23912c93935a - Implement engine runs queue
unc0rr
parents: 11438
diff changeset
   182
        queueExecution(currentConfig);
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   183
    end;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   184
end;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   185
10452
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   186
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
   187
var msg: ansistring;
10446
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   188
    i, hn, hedgehogsNumber: Longword;
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   189
    team: PTeam;
10450
bf9e30b4ef9b - Store index of color instead of its value
unc0rr
parents: 10448
diff changeset
   190
    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
   191
begin
10446
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   192
    with currentConfig do
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   193
    begin
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   194
        hedgehogsNumber:= 0;
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   195
        i:= 0;
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   196
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   197
        while (i < 8) and (teams[i].hogsNumber > 0) do
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   198
        begin
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   199
            inc(i);
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   200
            inc(hedgehogsNumber, teams[i].hogsNumber)
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   201
        end;
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   202
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   203
        // no free space for a team or reached hogs number maximum
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   204
        if (i > 7) or (hedgehogsNumber >= 48) then exit;
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   205
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   206
        team:= teamByName(teamName);
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   207
        if team = nil then exit;
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   208
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   209
        c:= getUnusedColor;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   210
10446
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   211
        teams[i]:= team^;
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   212
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   213
        if i = 0 then hn:= 4 else hn:= teams[i - 1].hogsNumber;
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   214
        if hn > 48 - hedgehogsNumber then hn:= 48 - hedgehogsNumber;
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   215
        teams[i].hogsNumber:= hn;
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   216
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   217
        teams[i].color:= c;
10446
7ae44f42a689 Perform some checks on team add
unc0rr
parents: 10444
diff changeset
   218
10452
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   219
        msg:= '0' + #10 + teamName;
10951
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents: 10892
diff changeset
   220
        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
   221
10452
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   222
        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
   223
        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
   224
10452
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   225
        msg:= teamName;
10951
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents: 10892
diff changeset
   226
        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
   227
    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
   228
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
   229
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   230
10452
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   231
procedure tryRemoveTeam(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
   232
var msg: ansistring;
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   233
    i: Longword;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   234
    tn: shortstring;
10444
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10432
diff changeset
   235
begin
10448
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   236
    with currentConfig do
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   237
    begin
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   238
        i:= 0;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   239
        tn:= teamName;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   240
        while (i < 8) and (teams[i].teamName <> tn) do
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   241
            inc(i);
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   242
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   243
        // team not found???
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   244
        if (i > 7) then exit;
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
        while (i < 7) and (teams[i + 1].hogsNumber > 0) do
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   247
        begin
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   248
            teams[i]:= teams[i + 1];
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   249
            inc(i)
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   250
        end;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   251
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   252
        teams[i].hogsNumber:= 0
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   253
    end;
4cb727e029fa - Allow to delete teams from config
unc0rr
parents: 10446
diff changeset
   254
10444
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10432
diff changeset
   255
    msg:= teamName;
47a6231f1fc1 Teams widget now allows to add and remove teams (basic implementation, no checks performed, no colors, no hedgehogs)
unc0rr
parents: 10432
diff changeset
   256
10951
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents: 10892
diff changeset
   257
    sendUI(mtRemovePlayingTeam, @msg[1], length(msg));
89a7f617e091 - Move protocol handling events to main thread through qt's main loop
unc0rr
parents: 10892
diff changeset
   258
    sendUI(mtAddTeam, @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
   259
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
   260
10452
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   261
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   262
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
   263
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
   264
    tn: shortstring;
11442
6e641b5453f9 Accept ammo scheme from network
unc0rr
parents: 11439
diff changeset
   265
    msg:  ansistring;
10452
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   266
begin
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   267
    with currentConfig do
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   268
    begin
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   269
        i:= 0;
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   270
        tn:= teamName;
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   271
        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
   272
            inc(i);
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   273
        // team not found???
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   274
        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
   275
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   276
        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
   277
        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
   278
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   279
        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
   280
        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
   281
    end
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   282
end;
03519fd9f98d Show team color in teams list widget, also allow to change it on mouse click
unc0rr
parents: 10450
diff changeset
   283
10456
6fd99bb73524 Theme can be changed
unc0rr
parents: 10452
diff changeset
   284
procedure setTheme(themeName: PChar); cdecl;
6fd99bb73524 Theme can be changed
unc0rr
parents: 10452
diff changeset
   285
begin
6fd99bb73524 Theme can be changed
unc0rr
parents: 10452
diff changeset
   286
    currentConfig.theme:= themeName
6fd99bb73524 Theme can be changed
unc0rr
parents: 10452
diff changeset
   287
end;
6fd99bb73524 Theme can be changed
unc0rr
parents: 10452
diff changeset
   288
10612
eb3c1a289a23 Script combobox.wiki
unc0rr
parents: 10456
diff changeset
   289
procedure setScript(scriptName: PChar); cdecl;
eb3c1a289a23 Script combobox.wiki
unc0rr
parents: 10456
diff changeset
   290
begin
11436
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11429
diff changeset
   291
    currentConfig.script:= scriptName
10612
eb3c1a289a23 Script combobox.wiki
unc0rr
parents: 10456
diff changeset
   292
end;
eb3c1a289a23 Script combobox.wiki
unc0rr
parents: 10456
diff changeset
   293
10819
57e21f7621b0 Send selected scheme config on engine initialization (WIP)
unc0rr
parents: 10612
diff changeset
   294
procedure setScheme(schemeName: PChar); cdecl;
57e21f7621b0 Send selected scheme config on engine initialization (WIP)
unc0rr
parents: 10612
diff changeset
   295
var scheme: PScheme;
57e21f7621b0 Send selected scheme config on engine initialization (WIP)
unc0rr
parents: 10612
diff changeset
   296
begin
57e21f7621b0 Send selected scheme config on engine initialization (WIP)
unc0rr
parents: 10612
diff changeset
   297
    scheme:= schemeByName(schemeName);
57e21f7621b0 Send selected scheme config on engine initialization (WIP)
unc0rr
parents: 10612
diff changeset
   298
57e21f7621b0 Send selected scheme config on engine initialization (WIP)
unc0rr
parents: 10612
diff changeset
   299
    if scheme <> nil then
57e21f7621b0 Send selected scheme config on engine initialization (WIP)
unc0rr
parents: 10612
diff changeset
   300
        currentConfig.scheme:= scheme^
57e21f7621b0 Send selected scheme config on engine initialization (WIP)
unc0rr
parents: 10612
diff changeset
   301
end;
57e21f7621b0 Send selected scheme config on engine initialization (WIP)
unc0rr
parents: 10612
diff changeset
   302
10888
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
   303
procedure setAmmo(ammoName: PChar); cdecl;
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
   304
var ammo: PAmmo;
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
   305
begin
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
   306
    ammo:= ammoByName(ammoName);
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
   307
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
   308
    if ammo <> nil then
10892
83a99e2f8b00 Make ammo scheme work
unc0rr
parents: 10888
diff changeset
   309
        currentConfig.ammo:= ammo^
10888
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
   310
end;
a04e04aaf599 Ammo schemes list, almost works
unc0rr
parents: 10819
diff changeset
   311
11436
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11429
diff changeset
   312
procedure netSetSeed(seed: shortstring);
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11429
diff changeset
   313
begin
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11429
diff changeset
   314
    if seed <> currentConfig.seed then
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11429
diff changeset
   315
    begin
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11429
diff changeset
   316
        currentConfig.seed:= seed;
11437
97e3e62ea5f9 Update seed, theme and script from net in UI
unc0rr
parents: 11436
diff changeset
   317
        sendUI(mtSeed, @seed[1], length(seed));
97e3e62ea5f9 Update seed, theme and script from net in UI
unc0rr
parents: 11436
diff changeset
   318
97e3e62ea5f9 Update seed, theme and script from net in UI
unc0rr
parents: 11436
diff changeset
   319
        getPreview()
11436
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11429
diff changeset
   320
    end
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11429
diff changeset
   321
end;
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11429
diff changeset
   322
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11429
diff changeset
   323
procedure netSetTheme(themeName: shortstring);
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11429
diff changeset
   324
begin
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11429
diff changeset
   325
    if themeName <> currentConfig.theme then
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11429
diff changeset
   326
    begin
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11429
diff changeset
   327
        currentConfig.theme:= themeName;
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11429
diff changeset
   328
        sendUI(mtTheme, @themeName[1], length(themeName))
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11429
diff changeset
   329
    end
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11429
diff changeset
   330
end;
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11429
diff changeset
   331
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11429
diff changeset
   332
procedure netSetScript(scriptName: shortstring);
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11429
diff changeset
   333
begin
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11429
diff changeset
   334
    if scriptName <> currentConfig.script then
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11429
diff changeset
   335
    begin
11438
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   336
        previewNeedsUpdate:= true;
11436
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11429
diff changeset
   337
        currentConfig.script:= scriptName;
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11429
diff changeset
   338
        sendUI(mtScript, @scriptName[1], length(scriptName))
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11429
diff changeset
   339
    end
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11429
diff changeset
   340
end;
80a9b14bb8d3 Some game config methods and signals
unc0rr
parents: 11429
diff changeset
   341
11438
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   342
procedure netSetFeatureSize(fsize: LongInt);
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   343
var s: shortstring;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   344
begin
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   345
    if fsize <> currentConfig.featureSize then
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   346
    begin
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   347
        previewNeedsUpdate:= true;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   348
        currentConfig.featureSize:= fsize;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   349
        s:= IntToStr(fsize);
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   350
        sendUI(mtFeatureSize, @s[1], length(s))
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   351
    end
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   352
end;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   353
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   354
procedure netSetMapGen(mapgen: LongInt);
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   355
var s: shortstring;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   356
begin
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   357
    if mapgen <> currentConfig.mapgen then
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   358
    begin
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   359
        previewNeedsUpdate:= true;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   360
        currentConfig.mapgen:= mapgen;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   361
        s:= IntToStr(mapgen);
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   362
        sendUI(mtMapGen, @s[1], length(s))
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   363
    end
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   364
end;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   365
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   366
procedure netSetMap(map: shortstring);
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   367
begin
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   368
    sendUI(mtMap, @map[1], length(map))
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   369
end;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   370
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   371
procedure netSetMazeSize(mazesize: LongInt);
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   372
var s: shortstring;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   373
begin
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   374
    if mazesize <> currentConfig.mazesize then
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   375
    begin
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   376
        previewNeedsUpdate:= true;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   377
        currentConfig.mazesize:= mazesize;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   378
        s:= IntToStr(mazesize);
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   379
        sendUI(mtMazeSize, @s[1], length(s))
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   380
    end
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   381
end;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   382
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   383
procedure netSetTemplate(template: LongInt);
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   384
var s: shortstring;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   385
begin
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   386
    if template <> currentConfig.template then
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   387
    begin
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   388
        previewNeedsUpdate:= true;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   389
        currentConfig.template:= template;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   390
        s:= IntToStr(template);
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   391
        sendUI(mtTemplate, @s[1], length(s))
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   392
    end
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   393
end;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   394
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   395
procedure updatePreviewIfNeeded;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   396
begin
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   397
    if previewNeedsUpdate then
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   398
        getPreview
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   399
end;
bca9afcc3a72 Handle some CFG parameters
unc0rr
parents: 11437
diff changeset
   400
11442
6e641b5453f9 Accept ammo scheme from network
unc0rr
parents: 11439
diff changeset
   401
procedure netSetAmmo(name: shortstring; definition: ansistring);
6e641b5453f9 Accept ammo scheme from network
unc0rr
parents: 11439
diff changeset
   402
var ammo: TAmmo;
6e641b5453f9 Accept ammo scheme from network
unc0rr
parents: 11439
diff changeset
   403
    i: LongInt;
6e641b5453f9 Accept ammo scheme from network
unc0rr
parents: 11439
diff changeset
   404
begin
6e641b5453f9 Accept ammo scheme from network
unc0rr
parents: 11439
diff changeset
   405
    ammo.ammoName:= name;
6e641b5453f9 Accept ammo scheme from network
unc0rr
parents: 11439
diff changeset
   406
    i:= length(definition) div 4;
6e641b5453f9 Accept ammo scheme from network
unc0rr
parents: 11439
diff changeset
   407
    ammo.a:= copy(definition, 1, i);
6e641b5453f9 Accept ammo scheme from network
unc0rr
parents: 11439
diff changeset
   408
    ammo.b:= copy(definition, i + 1, i);
6e641b5453f9 Accept ammo scheme from network
unc0rr
parents: 11439
diff changeset
   409
    ammo.c:= copy(definition, i * 2 + 1, i);
6e641b5453f9 Accept ammo scheme from network
unc0rr
parents: 11439
diff changeset
   410
    ammo.d:= copy(definition, i * 3 + 1, i);
6e641b5453f9 Accept ammo scheme from network
unc0rr
parents: 11439
diff changeset
   411
6e641b5453f9 Accept ammo scheme from network
unc0rr
parents: 11439
diff changeset
   412
    currentConfig.ammo:= ammo;
6e641b5453f9 Accept ammo scheme from network
unc0rr
parents: 11439
diff changeset
   413
    sendUI(mtAmmo, @name[1], length(name))
6e641b5453f9 Accept ammo scheme from network
unc0rr
parents: 11439
diff changeset
   414
end;
6e641b5453f9 Accept ammo scheme from network
unc0rr
parents: 11439
diff changeset
   415
11445
330c14f4ba69 Accept scheme from net
unc0rr
parents: 11443
diff changeset
   416
procedure netSetScheme(scheme: TScheme);
330c14f4ba69 Accept scheme from net
unc0rr
parents: 11443
diff changeset
   417
begin
330c14f4ba69 Accept scheme from net
unc0rr
parents: 11443
diff changeset
   418
    currentConfig.scheme:= scheme;
330c14f4ba69 Accept scheme from net
unc0rr
parents: 11443
diff changeset
   419
    sendUI(mtScheme, @scheme.schemeName[1], length(scheme.schemeName))
330c14f4ba69 Accept scheme from net
unc0rr
parents: 11443
diff changeset
   420
end;
330c14f4ba69 Accept scheme from net
unc0rr
parents: 11443
diff changeset
   421
11447
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   422
procedure netAddTeam(team: TTeam);
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   423
var msg: ansistring;
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   424
    i, hn, hedgehogsNumber: Longword;
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   425
    c: Longword;
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   426
begin
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   427
    with currentConfig do
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   428
    begin
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   429
        hedgehogsNumber:= 0;
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   430
        i:= 0;
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   431
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   432
        while (i < 8) and (teams[i].hogsNumber > 0) do
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   433
        begin
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   434
            inc(i);
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   435
            inc(hedgehogsNumber, teams[i].hogsNumber)
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   436
        end;
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   437
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   438
        // no free space for a team - server bug???
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   439
        if (i > 7) or (hedgehogsNumber >= 48) then exit;
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   440
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   441
        c:= getUnusedColor;
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   442
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   443
        teams[i]:= team;
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   444
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   445
        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
   446
        if hn > 48 - hedgehogsNumber then hn:= 48 - hedgehogsNumber;
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   447
        teams[i].hogsNumber:= hn;
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   448
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   449
        teams[i].color:= c;
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   450
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   451
        msg:= '0' + #10 + team.teamName;
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   452
        sendUI(mtAddPlayingTeam, @msg[1], length(msg));
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   453
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   454
        msg:= team.teamName + #10 + colorsSet[teams[i].color];
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   455
        sendUI(mtTeamColor, @msg[1], length(msg));
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   456
    end
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   457
end;
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   458
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   459
procedure netSetTeamColor(team: shortstring; color: Longword);
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   460
var i: Longword;
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   461
    msg:  ansistring;
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   462
begin
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   463
    with currentConfig do
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
        i:= 0;
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   466
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   467
        while (i < 8) and (teams[i].teamName <> team) do
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   468
            inc(i);
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   469
        // team not found???
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   470
        if (i > 7) then exit;
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   471
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   472
        teams[i].color:= color mod 9;
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   473
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   474
        msg:= team + #10 + colorsSet[teams[i].color];
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   475
        sendUI(mtTeamColor, @msg[1], length(msg))
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   476
    end
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   477
end;
6b04a266feee - Accept team and team color from net
unc0rr
parents: 11445
diff changeset
   478
10406
b5fd52ac760f Basic layout of frontlib, some more sdl bindings
unc0rr
parents:
diff changeset
   479
end.