hedgewars/uFLGameConfig.pas
branchqmlfrontend
changeset 11433 bca9afcc3a72
parent 11432 97e3e62ea5f9
child 11434 23912c93935a
equal deleted inserted replaced
11432:97e3e62ea5f9 11433:bca9afcc3a72
    19 procedure changeTeamColor(teamName: PChar; dir: LongInt); cdecl;
    19 procedure changeTeamColor(teamName: PChar; dir: LongInt); cdecl;
    20 
    20 
    21 procedure netSetSeed(seed: shortstring);
    21 procedure netSetSeed(seed: shortstring);
    22 procedure netSetTheme(themeName: shortstring);
    22 procedure netSetTheme(themeName: shortstring);
    23 procedure netSetScript(scriptName: shortstring);
    23 procedure netSetScript(scriptName: shortstring);
       
    24 procedure netSetFeatureSize(fsize: LongInt);
       
    25 procedure netSetMapGen(mapgen: LongInt);
       
    26 procedure netSetMap(map: shortstring);
       
    27 procedure netSetMazeSize(mazesize: LongInt);
       
    28 procedure netSetTemplate(template: LongInt);
       
    29 procedure updatePreviewIfNeeded;
    24 
    30 
    25 implementation
    31 implementation
    26 uses uFLIPC, hwengine, uFLUtils, uFLTeams, uFLData, uFLSChemes, uFLAmmo, uFLUICallback;
    32 uses uFLIPC, hwengine, uFLUtils, uFLTeams, uFLData, uFLSChemes, uFLAmmo, uFLUICallback;
    27 
    33 
    28 const
    34 const
    32 type
    38 type
    33     TGameConfig = record
    39     TGameConfig = record
    34             seed: shortstring;
    40             seed: shortstring;
    35             theme: shortstring;
    41             theme: shortstring;
    36             script: shortstring;
    42             script: shortstring;
       
    43             map: shortstring;
    37             scheme: TScheme;
    44             scheme: TScheme;
    38             ammo: TAmmo;
    45             ammo: TAmmo;
    39             mapgen: Longint;
    46             mapgen: LongInt;
       
    47             featureSize: LongInt;
       
    48             mazesize: LongInt;
       
    49             template: LongInt;
    40             gameType: TGameType;
    50             gameType: TGameType;
    41             teams: array[0..7] of TTeam;
    51             teams: array[0..7] of TTeam;
    42             arguments: array[0..Pred(MAXARGS)] of shortstring;
    52             arguments: array[0..Pred(MAXARGS)] of shortstring;
    43             argv: array[0..Pred(MAXARGS)] of PChar;
    53             argv: array[0..Pred(MAXARGS)] of PChar;
    44             argumentsNumber: Longword;
    54             argumentsNumber: Longword;
    45             end;
    55             end;
    46     PGameConfig = ^TGameConfig;
    56     PGameConfig = ^TGameConfig;
    47 
    57 
    48 var
    58 var
    49     currentConfig: TGameConfig;
    59     currentConfig: TGameConfig;
       
    60     previewNeedsUpdate: boolean;
    50 
    61 
    51 function getScriptPath(scriptName: shortstring): shortstring;
    62 function getScriptPath(scriptName: shortstring): shortstring;
    52 begin
    63 begin
    53     getScriptPath:= '/Scripts/Multiplayer/' + scriptName + '.lua'
    64     getScriptPath:= '/Scripts/Multiplayer/' + scriptName + '.lua'
    54 end;
    65 end;
   177 end;
   188 end;
   178 
   189 
   179 
   190 
   180 procedure getPreview; cdecl;
   191 procedure getPreview; cdecl;
   181 begin
   192 begin
       
   193     previewNeedsUpdate:= false;
       
   194 
   182     with currentConfig do
   195     with currentConfig do
   183     begin
   196     begin
   184         gameType:= gtPreview;
   197         gameType:= gtPreview;
   185         arguments[0]:= '';
   198         arguments[0]:= '';
   186         arguments[1]:= '--internal';
   199         arguments[1]:= '--internal';
   353 
   366 
   354 procedure netSetScript(scriptName: shortstring);
   367 procedure netSetScript(scriptName: shortstring);
   355 begin
   368 begin
   356     if scriptName <> currentConfig.script then
   369     if scriptName <> currentConfig.script then
   357     begin
   370     begin
       
   371         previewNeedsUpdate:= true;
   358         currentConfig.script:= scriptName;
   372         currentConfig.script:= scriptName;
   359         sendUI(mtScript, @scriptName[1], length(scriptName))
   373         sendUI(mtScript, @scriptName[1], length(scriptName))
   360     end
   374     end
   361 end;
   375 end;
   362 
   376 
       
   377 procedure netSetFeatureSize(fsize: LongInt);
       
   378 var s: shortstring;
       
   379 begin
       
   380     if fsize <> currentConfig.featureSize then
       
   381     begin
       
   382         previewNeedsUpdate:= true;
       
   383         currentConfig.featureSize:= fsize;
       
   384         s:= IntToStr(fsize);
       
   385         sendUI(mtFeatureSize, @s[1], length(s))
       
   386     end
       
   387 end;
       
   388 
       
   389 procedure netSetMapGen(mapgen: LongInt);
       
   390 var s: shortstring;
       
   391 begin
       
   392     if mapgen <> currentConfig.mapgen then
       
   393     begin
       
   394         previewNeedsUpdate:= true;
       
   395         currentConfig.mapgen:= mapgen;
       
   396         s:= IntToStr(mapgen);
       
   397         sendUI(mtMapGen, @s[1], length(s))
       
   398     end
       
   399 end;
       
   400 
       
   401 procedure netSetMap(map: shortstring);
       
   402 begin
       
   403     sendUI(mtMap, @map[1], length(map))
       
   404 end;
       
   405 
       
   406 procedure netSetMazeSize(mazesize: LongInt);
       
   407 var s: shortstring;
       
   408 begin
       
   409     if mazesize <> currentConfig.mazesize then
       
   410     begin
       
   411         previewNeedsUpdate:= true;
       
   412         currentConfig.mazesize:= mazesize;
       
   413         s:= IntToStr(mazesize);
       
   414         sendUI(mtMazeSize, @s[1], length(s))
       
   415     end
       
   416 end;
       
   417 
       
   418 procedure netSetTemplate(template: LongInt);
       
   419 var s: shortstring;
       
   420 begin
       
   421     if template <> currentConfig.template then
       
   422     begin
       
   423         previewNeedsUpdate:= true;
       
   424         currentConfig.template:= template;
       
   425         s:= IntToStr(template);
       
   426         sendUI(mtTemplate, @s[1], length(s))
       
   427     end
       
   428 end;
       
   429 
       
   430 procedure updatePreviewIfNeeded;
       
   431 begin
       
   432     if previewNeedsUpdate then
       
   433         getPreview
       
   434 end;
       
   435 
   363 end.
   436 end.