Changeset 143 for trunk/Start.pas
- Timestamp:
- May 8, 2018, 4:37:34 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Start.pas
r137 r143 70 70 procedure ReplayBtnClick(Sender: TObject); 71 71 public 72 BrainPicture: array [0 .. maxBrain - 1] of TBitmap;73 72 EmptyPicture: TBitmap; 74 73 procedure UpdateFormerGames; 75 74 procedure UpdateMaps; 76 75 private 77 WorldSize, StartLandMass, MaxTurn, AutoEnemies, AutoDiff, MultiControl, 78 MiniWidth, MiniHeight, SelectedAction, Page, ShowTab, Tab, Diff0, 79 bixDefault, nMapLandTiles, nMapStartPositions, LoadTurn, LastTurn, 76 WorldSize: Integer; 77 StartLandMass: Integer; 78 MaxTurn: Integer; 79 AutoEnemies: Integer; 80 AutoDiff: Integer; 81 MultiControl: Integer; 82 MiniWidth: Integer; 83 MiniHeight: Integer; 84 SelectedAction: Integer; 85 Page: Integer; 86 ShowTab: Integer; 87 Tab: Integer; 88 Diff0: Integer; 89 bixDefault: Integer; 90 nMapLandTiles: Integer; 91 nMapStartPositions: Integer; 92 LoadTurn: Integer; 93 LastTurn: Integer; 80 94 { last turn of selected former game } 81 SlotAvailable, bixPopup: integer; { brain concerned by brain context menu } 95 SlotAvailable: Integer; 96 bixPopup: Integer; { brain concerned by brain context menu } 82 97 ListIndex: array [0 .. 3] of integer; 83 98 MapFileName: string; … … 186 201 r0, r1: HRgn; 187 202 Location: TPoint; 203 AIBrains: TBrains; 188 204 begin 189 205 LoadConfig; … … 195 211 196 212 bixDefault := -1; 197 for i := bixRandom to nBrain- 1 do198 if AnsiCompareFileName(DefaultAI, Brain [i].FileName) = 0 then213 for i := Brains.IndexOf(BrainRandom) to Brains.Count - 1 do 214 if AnsiCompareFileName(DefaultAI, Brains[i].FileName) = 0 then 199 215 bixDefault := i; 200 if (bixDefault = bixRandom) and (nBrain < bixFirstAI +2) then216 if (bixDefault = Brains.IndexOf(BrainRandom)) and (Brains.GetKindCount(btAI) < 2) then 201 217 bixDefault := -1; 202 if (bixDefault < 0) and (nBrain > bixFirstAI) then 203 bixDefault := bixFirstAI; // default AI not found, use any 218 if (bixDefault < 0) and (Brains.GetKindCount(btAI) > 0) then 219 begin 220 AIBrains := TBrains.Create(False); 221 Brains.GetByKind(btAI, AIBrains); 222 bixDefault := Brains.IndexOf(Brains[0]); 223 AIBrains.Free; 224 end; // default AI not found, use any 204 225 205 226 DirectDlg.Left := (Screen.Width - DirectDlg.Width) div 2; … … 269 290 CustomizeBtn.ButtonIndex := 2; 270 291 271 Brain Picture[0]:= TBitmap.Create;272 Brain Picture[0].SetSize(64, 64);273 BitBlt(Brain Picture[0].Canvas.Handle, 0, 0, 64, 64,292 Brains[0].Picture := TBitmap.Create; 293 Brains[0].Picture.SetSize(64, 64); 294 BitBlt(Brains[0].Picture.Canvas.Handle, 0, 0, 64, 64, 274 295 GrExt[HGrSystem2].Data.Canvas.Handle, 1, 111, SRCCOPY); 275 Brain Picture[1]:= TBitmap.Create;276 Brain Picture[1].SetSize(64, 64);277 BitBlt(Brain Picture[1].Canvas.Handle, 0, 0, 64, 64,296 Brains[1].Picture := TBitmap.Create; 297 Brains[1].Picture.SetSize(64, 64); 298 BitBlt(Brains[1].Picture.Canvas.Handle, 0, 0, 64, 64, 278 299 GrExt[HGrSystem2].Data.Canvas.Handle, 66, 111, SRCCOPY); 279 Brain Picture[2]:= TBitmap.Create;280 Brain Picture[2].SetSize(64, 64);281 BitBlt(Brain Picture[2].Canvas.Handle, 0, 0, 64, 64,300 Brains[2].Picture := TBitmap.Create; 301 Brains[2].Picture.SetSize(64, 64); 302 BitBlt(Brains[2].Picture.Canvas.Handle, 0, 0, 64, 64, 282 303 GrExt[HGrSystem2].Data.Canvas.Handle, 131, 111, SRCCOPY); 283 Brain Picture[3]:= TBitmap.Create;284 Brain Picture[3].SetSize(64, 64);285 BitBlt(Brain Picture[3].Canvas.Handle, 0, 0, 64, 64,304 Brains[3].Picture := TBitmap.Create; 305 Brains[3].Picture.SetSize(64, 64); 306 BitBlt(Brains[3].Picture.Canvas.Handle, 0, 0, 64, 64, 286 307 GrExt[HGrSystem2].Data.Canvas.Handle, 131, 46, SRCCOPY); 287 for i := bixFirstAI to nBrain - 1 do begin 288 BrainPicture[i] := TBitmap.Create; 289 if not LoadGraphicFile(BrainPicture[i], HomeDir + 'AI' + DirectorySeparator + 290 Brain[i].FileName + DirectorySeparator + Brain[i].FileName + '.png', 291 gfNoError) then begin 292 BrainPicture[i].SetSize(64, 64); 293 with BrainPicture[i].Canvas do begin 308 309 AIBrains := TBrains.Create(False); 310 Brains.GetByKind(btAI, AIBrains); 311 for i := 0 to AIBrains.Count - 1 do 312 with AIBrains[I] do 313 begin 314 AIBrains[i].Picture := TBitmap.Create; 315 if not LoadGraphicFile(AIBrains[i].Picture, HomeDir + 'AI' + DirectorySeparator + 316 FileName + DirectorySeparator + FileName + '.png', gfNoError) then begin 317 AIBrains[i].Picture.SetSize(64, 64); 318 with AIBrains[i].Picture.Canvas do begin 294 319 Brush.Color := $904830; 295 320 FillRect(Rect(0, 0, 64, 64)); … … 297 322 Font.Style := []; 298 323 Font.Color := $5FDBFF; 299 Textout(32 - TextWidth( Brain[i].FileName) div 2,300 32 - TextHeight( Brain[i].FileName) div 2, Brain[i].FileName);324 Textout(32 - TextWidth(FileName) div 2, 325 32 - TextHeight(FileName) div 2, FileName); 301 326 end; 302 327 end; 303 328 end; 329 AIBrains.Free; 304 330 305 331 EmptyPicture := TBitmap.Create; … … 318 344 InitButtons; 319 345 320 bixView[0] := bixTerm;346 bixView[0] := Brains.IndexOf(BrainTerm); 321 347 SlotAvailable := -1; 322 348 Tab := 2; … … 333 359 334 360 procedure TStartDlg.FormDestroy(Sender: TObject); 335 var336 i: integer;337 361 begin 338 362 FreeAndNil(FormerGames); … … 341 365 FreeAndNil(EmptyPicture); 342 366 FreeAndNil(LogoBuffer); 343 for i := 0 to nBrain - 1 do344 FreeAndNil(BrainPicture[i]);345 367 end; 346 368 … … 624 646 begin 625 647 if bixView[i] >= 0 then 626 FrameImage(Canvas, Brain Picture[bixView[i]], xBrain[i], yBrain[i],648 FrameImage(Canvas, Brains[bixView[i]].Picture, xBrain[i], yBrain[i], 627 649 64, 64, 0, 0, true) 628 650 else 629 651 FrameImage(Canvas, EmptyPicture, xBrain[i], yBrain[i], 64, 64, 630 652 0, 0, true); 631 if bixView[i] >= bixTermthen653 if Brains[bixView[i]].Kind in [btTerm, btRandom, btAI] then 632 654 begin 633 655 BitBlt(Canvas.Handle, xBrain[i] - 18, yBrain[i] + 19, 12, 14, … … 658 680 begin 659 681 DiffUpBtn[i].Hint := Format(Phrases.Lookup('STARTCONTROLS', 9), 660 [Brain [bixView[i]].Name]);682 [Brains[bixView[i]].Name]); 661 683 DiffDownBtn[i].Hint := DiffUpBtn[i].Hint; 662 684 end … … 681 703 yMain + 164 { y0Mini-77 } , Phrases.Lookup('STARTCONTROLS', 16)); 682 704 if AutoDiff = 1 then 683 FrameImage(Canvas, Brain Picture[bixBeginner], xDefault, yDefault, 64,705 FrameImage(Canvas, BrainBeginner.Picture, xDefault, yDefault, 64, 684 706 64, 0, 0, false) 685 707 else 686 FrameImage(Canvas, Brain Picture[bixDefault], xDefault, yDefault, 64, 64,708 FrameImage(Canvas, Brains[bixDefault].Picture, xDefault, yDefault, 64, 64, 687 709 0, 0, true); 688 710 DLine(Canvas, 56, 272, y0Mini + 61 + 19, MainTexture.clBevelLight, … … 895 917 else GameCount := 0; 896 918 897 if (AutoDiff < 0) and ( bixView[0] = bixNoTerm) then919 if (AutoDiff < 0) and (Brains[bixView[0]].Kind = btNoTerm) then 898 920 FileName := 'Round' + IntToStr(GetProcessID()) 899 921 else begin … … 913 935 Reg.WriteString('Control' + IntToStr(i), '') 914 936 else Reg.WriteString('Control' + IntToStr(i), 915 Brain [bixView[i]].FileName);937 Brains[bixView[i]].FileName); 916 938 WriteInteger('Diff' + IntToStr(i), Difficulty[i]); 917 939 end; … … 922 944 if AutoDiff > 0 then 923 945 begin 924 WriteString('DefaultAI', Brain [bixDefault].FileName);946 WriteString('DefaultAI', Brains[bixDefault].FileName); 925 947 SlotAvailable := 0; // bixView will be invalid hereafter 926 bixView[0] := bixTerm;948 bixView[0] := Brains.IndexOf(BrainTerm); 927 949 Difficulty[0] := PlayerAutoDiff[AutoDiff]; 928 950 for i := 1 to nPl - 1 do 929 951 if (Page = pgStartRandom) and (i <= AutoEnemies) or 930 952 (Page = pgStartMap) and (i < nMapStartPositions) then begin 931 if AutoDiff = 1 then bixView[i] := bixBeginner953 if AutoDiff = 1 then bixView[i] := Brains.IndexOf(BrainBeginner) 932 954 else bixView[i] := bixDefault; 933 955 Difficulty[i] := EnemyAutoDiff[AutoDiff]; … … 935 957 end else begin 936 958 for i := 6 to 8 do 937 if ( bixView[0] <> bixNoTerm) and (MultiControl and (1 shl i) <> 0)959 if (Brains[bixView[0]].Kind <> btNoTerm) and (MultiControl and (1 shl i) <> 0) 938 960 then begin 939 961 bixView[i + 3] := bixView[i]; … … 1218 1240 else 1219 1241 begin 1220 Brain [bixView[bixPopup]].Flags := Brain[bixView[bixPopup]].Flags and1242 Brains[bixView[bixPopup]].Flags := Brains[bixView[bixPopup]].Flags and 1221 1243 not fUsed; 1222 1244 bixView[bixPopup] := TMenuItem(Sender).Tag; 1223 DiffUpBtn[bixPopup].Visible := bixView[bixPopup] >= bixTerm;1224 DiffDownBtn[bixPopup].Visible := bixView[bixPopup] >= bixTerm;1245 DiffUpBtn[bixPopup].Visible := Brains[bixView[bixPopup]].Kind in [btTerm, btRandom, btAI]; 1246 DiffDownBtn[bixPopup].Visible := Brains[bixView[bixPopup]].Kind in [btTerm, btRandom, btAI]; 1225 1247 if bixPopup in OfferMultiple then 1226 1248 begin 1227 MultiBtn[bixPopup].Visible := bixView[bixPopup] >= bixTerm;1249 MultiBtn[bixPopup].Visible := Brains[bixView[bixPopup]].Kind in [btTerm, btRandom, btAI]; 1228 1250 MultiBtn[bixPopup].ButtonIndex := 2 + (MultiControl shr bixPopup) and 1; 1229 1251 end; 1230 Brain [bixView[bixPopup]].Flags := Brain[bixView[bixPopup]].Flags or fUsed;1231 if bixView[bixPopup] < bixTermthen1252 Brains[bixView[bixPopup]].Flags := Brains[bixView[bixPopup]].Flags or fUsed; 1253 if Brains[bixView[bixPopup]].Kind in [btNoTerm, btSuperVirtual] then 1232 1254 Difficulty[bixPopup] := 0 { supervisor } 1233 1255 else … … 1238 1260 if (bixPopup = 0) and (MapFileName <> '') then 1239 1261 ChangePage(Page); 1240 if bixView[bixPopup] = bixNoTerm then1262 if Brains[bixView[bixPopup]].Kind = btNoTerm then 1241 1263 begin // turn all local players off 1242 1264 for i := 1 to nPlOffered - 1 do 1243 if bixView[i] = bixTerm then1265 if Brains[bixView[i]].Kind = btTerm then 1244 1266 begin 1245 1267 bixView[i] := -1; … … 1256 1278 DiffUpBtn[i].top + 25); 1257 1279 end; 1258 Brain [bixTerm].Flags := Brain[bixTerm].Flags and not fUsed;1280 BrainTerm.Flags := BrainTerm.Flags and not fUsed; 1259 1281 end; 1260 1282 SmartInvalidate(xBrain[bixPopup] - 31, yBrain[bixPopup] - 1, … … 1267 1289 i, FixedLines: integer; 1268 1290 m: TMenuItem; 1291 AIBrains: TBrains; 1269 1292 1270 1293 procedure OfferBrain(Index: integer); … … 1276 1299 m.Caption := Phrases.Lookup('NOMOD') 1277 1300 else 1278 m.Caption := Brain [Index].Name;1301 m.Caption := Brains[Index].Name; 1279 1302 m.Tag := Index; 1280 1303 m.OnClick := BrainClick; … … 1297 1320 begin // select default AI 1298 1321 FixedLines := 0; 1299 if nBrain >= bixFirstAI +2 then1322 if Brains.GetKindCount(btAI) >= 2 then 1300 1323 begin 1301 OfferBrain( bixRandom);1324 OfferBrain(Brains.IndexOf(BrainRandom)); 1302 1325 inc(FixedLines) 1303 1326 end; 1304 for i := bixFirstAI to nBrain - 1 do // offer available AIs 1305 if Brain[i].Flags and fMultiple <> 0 then 1306 OfferBrain(i); 1327 AIBrains := TBrains.Create(False); 1328 Brains.GetByKind(btAI, AIBrains); 1329 for i := 0 to AIBrains.Count - 1 do // offer available AIs 1330 if AIBrains[i].Flags and fMultiple <> 0 then 1331 OfferBrain(Brains.IndexOf(AIBrains[i])); 1332 AIBrains.Free; 1307 1333 end 1308 1334 else … … 1314 1340 inc(FixedLines); 1315 1341 end; 1316 for i := bixTermdownto 0 do // offer game interfaces1317 if (bixPopup = 0) or ( i = bixTerm) and (bixView[0] <> bixNoTerm) then1342 for i := Brains.IndexOf(BrainTerm) downto 0 do // offer game interfaces 1343 if (bixPopup = 0) or (Brains[i].Kind = btTerm) and (Brains[bixView[0]].Kind <> btNoTerm) then 1318 1344 begin 1319 1345 OfferBrain(i); … … 1326 1352 PopupMenu1.Items.Add(m); 1327 1353 inc(FixedLines); 1328 if nBrain >= bixFirstAI +2 then1329 begin 1330 OfferBrain( bixRandom);1354 if Brains.GetKindCount(btAI) >= 2 then 1355 begin 1356 OfferBrain(Brains.IndexOf(BrainRandom)); 1331 1357 inc(FixedLines); 1332 1358 end; 1333 for i := bixFirstAI to nBrain - 1 do // offer available AIs 1334 if (Brain[i].Flags and fMultiple <> 0) or (Brain[i].Flags and fUsed = 0) 1359 AIBrains := TBrains.Create(False); 1360 Brains.GetByKind(btAI, AIBrains); 1361 for i := 0 to AIBrains.Count - 1 do // offer available AIs 1362 if (AIBrains[i].Flags and fMultiple <> 0) or (AIBrains[i].Flags and fUsed = 0) 1335 1363 or (i = bixView[bixPopup]) then 1336 OfferBrain(i); 1364 OfferBrain(Brains.IndexOf(AIBrains[i])); 1365 AIBrains.Free; 1337 1366 end; 1338 1367 end … … 1397 1426 if i = 0 then 1398 1427 begin 1399 bixView[0] := bixSuper_Virtual;1428 bixView[0] := Brains.IndexOf(BrainSuperVirtual); 1400 1429 Difficulty[0] := 0 1401 1430 end; 1402 if bixView[0] < bixTermthen1431 if Brains[bixView[0]].Kind in [btNoTerm, btSuperVirtual] then 1403 1432 inc(i); 1404 1433 if i > nPl then … … 1421 1450 Difficulty[p1] := ReadInteger('Diff' + IntToStr(p1)); 1422 1451 if s <> '' then 1423 for j := 0 to nBrain- 1 do1424 if AnsiCompareFileName(s, Brain [j].FileName) = 0 then1452 for j := 0 to Brains.Count - 1 do 1453 if AnsiCompareFileName(s, Brains[j].FileName) = 0 then 1425 1454 bixView[p1] := j; 1426 1455 end; … … 1441 1470 SlotAvailable := InitAlive[i]; 1442 1471 for i := 0 to nPlOffered - 1 do 1443 if (AutoDiff < 0) and ( bixView[i] >= bixTerm) then1472 if (AutoDiff < 0) and (Brains[bixView[i]].Kind in [btTerm, btRandom, btAI]) then 1444 1473 begin 1445 1474 DiffUpBtn[i].Tag := 768; … … 1452 1481 end; 1453 1482 for i := 6 to 8 do 1454 if (AutoDiff < 0) and ( bixView[i] >= bixTerm) then1483 if (AutoDiff < 0) and (Brains[bixView[i]].Kind in [btTerm, btRandom, btAI]) then 1455 1484 begin 1456 1485 MultiBtn[i].Tag := 768; … … 1593 1622 (x >= xDefault) and (y >= yDefault) and (x < xDefault + 64) and 1594 1623 (y < yDefault + 64) then 1595 if nBrain < bixFirstAI +2 then1624 if Brains.GetKindCount(btAI) < 2 then 1596 1625 SimpleMessage(Phrases.Lookup('NOALTAI')) 1597 1626 else
Note:
See TracChangeset
for help on using the changeset viewer.