hedgewars/uFLGameConfig.pas
branchqmlfrontend
changeset 11434 23912c93935a
parent 11433 bca9afcc3a72
child 11437 6e641b5453f9
equal deleted inserted replaced
11433:bca9afcc3a72 11434:23912c93935a
    26 procedure netSetMap(map: shortstring);
    26 procedure netSetMap(map: shortstring);
    27 procedure netSetMazeSize(mazesize: LongInt);
    27 procedure netSetMazeSize(mazesize: LongInt);
    28 procedure netSetTemplate(template: LongInt);
    28 procedure netSetTemplate(template: LongInt);
    29 procedure updatePreviewIfNeeded;
    29 procedure updatePreviewIfNeeded;
    30 
    30 
       
    31 procedure sendConfig(config: PGameConfig);
       
    32 
    31 implementation
    33 implementation
    32 uses uFLIPC, hwengine, uFLUtils, uFLTeams, uFLData, uFLSChemes, uFLAmmo, uFLUICallback;
    34 uses uFLIPC, uFLUtils, uFLTeams, uFLData, uFLSChemes, uFLAmmo, uFLUICallback, uFLRunQueue;
    33 
       
    34 const
       
    35     MAXCONFIGS = 5;
       
    36     MAXARGS = 32;
       
    37 
       
    38 type
       
    39     TGameConfig = record
       
    40             seed: shortstring;
       
    41             theme: shortstring;
       
    42             script: shortstring;
       
    43             map: shortstring;
       
    44             scheme: TScheme;
       
    45             ammo: TAmmo;
       
    46             mapgen: LongInt;
       
    47             featureSize: LongInt;
       
    48             mazesize: LongInt;
       
    49             template: LongInt;
       
    50             gameType: TGameType;
       
    51             teams: array[0..7] of TTeam;
       
    52             arguments: array[0..Pred(MAXARGS)] of shortstring;
       
    53             argv: array[0..Pred(MAXARGS)] of PChar;
       
    54             argumentsNumber: Longword;
       
    55             end;
       
    56     PGameConfig = ^TGameConfig;
       
    57 
    35 
    58 var
    36 var
    59     currentConfig: TGameConfig;
    37     currentConfig: TGameConfig;
    60     previewNeedsUpdate: boolean;
    38     previewNeedsUpdate: boolean;
    61 
    39 
    73     gtPreview: begin
    51     gtPreview: begin
    74             if script <> 'Normal' then
    52             if script <> 'Normal' then
    75                 ipcToEngine('escript ' + getScriptPath(script));
    53                 ipcToEngine('escript ' + getScriptPath(script));
    76             ipcToEngine('eseed ' + seed);
    54             ipcToEngine('eseed ' + seed);
    77             ipcToEngine('e$mapgen ' + intToStr(mapgen));
    55             ipcToEngine('e$mapgen ' + intToStr(mapgen));
       
    56             ipcToEngine('e$template_filter ' + intToStr(template));
       
    57             ipcToEngine('e$feature_size ' + intToStr(featureSize));
    78         end;
    58         end;
    79     gtLocal: begin
    59     gtLocal: begin
    80             if script <> 'Normal' then
    60             if script <> 'Normal' then
    81                 ipcToEngine('escript ' + getScriptPath(script));
    61                 ipcToEngine('escript ' + getScriptPath(script));
    82             ipcToEngine('eseed ' + seed);
    62             ipcToEngine('eseed ' + seed);
    83             ipcToEngine('e$mapgen ' + intToStr(mapgen));
    63             ipcToEngine('e$mapgen ' + intToStr(mapgen));
       
    64             ipcToEngine('e$template_filter ' + intToStr(template));
       
    65             ipcToEngine('e$feature_size ' + intToStr(featureSize));
    84             ipcToEngine('e$theme ' + theme);
    66             ipcToEngine('e$theme ' + theme);
    85 
    67 
    86             sendSchemeConfig(scheme);
    68             sendSchemeConfig(scheme);
    87 
    69 
    88             i:= 0;
    70             i:= 0;
    98 
    80 
    99     ipcToEngine('!');
    81     ipcToEngine('!');
   100 end;
    82 end;
   101 end;
    83 end;
   102 
    84 
   103 procedure queueExecution;
       
   104 var pConfig: PGameConfig;
       
   105     i: Longword;
       
   106 begin
       
   107     new(pConfig);
       
   108     pConfig^:= currentConfig;
       
   109 
       
   110     with pConfig^ do
       
   111         for i:= 0 to Pred(MAXARGS) do
       
   112         begin
       
   113             if arguments[i][0] = #255 then 
       
   114                 arguments[i][255]:= #0
       
   115             else
       
   116                 arguments[i][byte(arguments[i][0]) + 1]:= #0;
       
   117             argv[i]:= @arguments[i][1]
       
   118         end;
       
   119 
       
   120     RunEngine(pConfig^.argumentsNumber, @pConfig^.argv);
       
   121 
       
   122     sendConfig(pConfig)
       
   123 end;
       
   124 
       
   125 procedure resetGameConfig; cdecl;
    85 procedure resetGameConfig; cdecl;
   126 var i: Longword;
    86 var i: Longword;
   127 begin
    87 begin
   128     with currentConfig do
    88     with currentConfig do
   129     begin
    89     begin
   181         teams[0].color:= 0;
   141         teams[0].color:= 0;
   182         teams[1]:= createRandomTeam;
   142         teams[1]:= createRandomTeam;
   183         teams[1].color:= 1;
   143         teams[1].color:= 1;
   184         teams[1].botLevel:= 3;
   144         teams[1].botLevel:= 3;
   185 
   145 
   186         queueExecution;
   146         queueExecution(currentConfig);
   187     end;
   147     end;
   188 end;
   148 end;
   189 
   149 
   190 
   150 
   191 procedure getPreview; cdecl;
   151 procedure getPreview; cdecl;
   198         arguments[0]:= '';
   158         arguments[0]:= '';
   199         arguments[1]:= '--internal';
   159         arguments[1]:= '--internal';
   200         arguments[2]:= '--landpreview';
   160         arguments[2]:= '--landpreview';
   201         argumentsNumber:= 3;
   161         argumentsNumber:= 3;
   202 
   162 
   203         queueExecution;
   163         queueExecution(currentConfig);
   204     end;
   164     end;
   205 end;
   165 end;
   206 
   166 
   207 procedure runLocalGame; cdecl;
   167 procedure runLocalGame; cdecl;
   208 begin
   168 begin
   212         arguments[0]:= '';
   172         arguments[0]:= '';
   213         arguments[1]:= '--internal';
   173         arguments[1]:= '--internal';
   214         arguments[2]:= '--nomusic';
   174         arguments[2]:= '--nomusic';
   215         argumentsNumber:= 3;
   175         argumentsNumber:= 3;
   216 
   176 
   217         queueExecution;
   177         queueExecution(currentConfig);
   218     end;
   178     end;
   219 end;
   179 end;
   220 
   180 
   221 procedure tryAddTeam(teamName: PChar); cdecl;
   181 procedure tryAddTeam(teamName: PChar); cdecl;
   222 var msg: ansistring;
   182 var msg: ansistring;