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