Skip to content

Commit 61029e6

Browse files
committed
big scanning works surprising well! #1
1 parent 43f4b3d commit 61029e6

File tree

2 files changed

+38
-15
lines changed

2 files changed

+38
-15
lines changed

src/mainform.pas

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ TFormMain = class(TForm)
4242
procedure ScanScripts(); // scan scripts folder in the game & update UI
4343
procedure LaunchGame( mod_name:string; params: string );
4444

45+
procedure MakeAIGood( mod_name: string );
4546
procedure ActivateMod( mod_name: string );
4647
procedure DeactivateMod( mod_name: string );
4748

@@ -124,7 +125,7 @@ function TFormMain.HasModAI(mod_name: string): integer;
124125
result := ScanZbigsForAI( mod_path );
125126

126127
// write it so that I don't have to do zbig scan again.
127-
//mconf.SetValue( 'has_ai', result );
128+
mconf.SetValue( 'has_ai', result );
128129
end;
129130
// else, the result read from the config is correct.
130131

@@ -143,16 +144,22 @@ function TFormMain.ScanZbigsForAI(mod_path: string): integer;
143144

144145
Repeat
145146
// Scan the contents
146-
ShowMessage( info.name );
147-
148-
big.Create;
149-
big.LoadFile( info.name );
150-
cnt := big.GetNumFiles;
151-
for i := 0 to cnt-1 do
152-
begin
153-
f := big.GetFileInfo( i );
154-
// f.Filename should be used :)
155-
end;
147+
big := TBIGPackage.Create;
148+
big.LoadFile( mod_path + info.name );
149+
if big.IsValid then
150+
begin
151+
// scan through file list, find AI related files.
152+
cnt := big.GetNumFiles;
153+
for i := 0 to cnt-1 do
154+
begin
155+
f := big.GetFileInfo( i );
156+
if pos( 'skirmishscripts', lowercase( f.filename ) ) <> 0 then
157+
begin
158+
result := 1; // found it!!
159+
break;
160+
end;
161+
end;
162+
end;
156163
big.Free;
157164
Until FindNext(info) <> 0;
158165

@@ -195,6 +202,8 @@ procedure TFormMain.LaunchGame( mod_name: string; params: string );
195202
// Set the mod as active
196203
ActivateMod( mod_name );
197204

205+
MakeAIGood( mod_name );
206+
198207
// Run the mod
199208
//ShellExecute( 0, 'open', PChar(game_exe), PChar(params), nil, SW_NORMAL );
200209
output := '';
@@ -204,6 +213,20 @@ procedure TFormMain.LaunchGame( mod_name: string; params: string );
204213
DeactivateMod( mod_name );
205214
end;
206215

216+
procedure TFormMain.MakeAIGood( mod_name: string );
217+
var
218+
has_ai: integer;
219+
begin
220+
// Make AI good by activating the scripts folder in ZH dir.
221+
has_ai := integer( ModList.Items.Objects[ ModList.ItemIndex ] );
222+
223+
// if has AI and mod ai needs activation...
224+
if (has_ai <> 0) and (BtnMod.Enabled) then
225+
BtnMod.Click
226+
else if (has_ai = 0) and (BtnRestore.Enabled) then
227+
BtnRestore.Click;
228+
end;
229+
207230
procedure TFormMain.ActivateMod( mod_name: string );
208231
var
209232
i : Integer;

src/settings.pas

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,23 @@ TSettings = class
3535
dscript: string;
3636
//moddir: string;
3737

38-
constructor create();
39-
procedure free();
38+
constructor create;
39+
procedure free;
4040

4141
property
4242
game_dir: string read GetGameDir write SetGameDir;
4343
end;
4444

4545
implementation
4646

47-
constructor TSettings.create();
47+
constructor TSettings.create;
4848
begin
4949
conf := TJSONConfig.Create(nil);
5050
LoadConf();
5151
GetDirs();
5252
end;
5353

54-
procedure TSettings.free();
54+
procedure TSettings.free;
5555
begin
5656
conf.free();
5757
end;

0 commit comments

Comments
 (0)