Changeset 144 for trunk/Start.pas
- Timestamp:
- May 11, 2018, 11:57:25 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Start.pas
r143 r144 7 7 GameServer, Messg, ButtonBase, ButtonA, ButtonC, ButtonB, Area, Math, 8 8 LCLIntf, LCLType, SysUtils, Classes, Graphics, Controls, Forms, StdCtrls, 9 Menus, Registry, DrawDlg ;9 Menus, Registry, DrawDlg, fgl; 10 10 11 11 const … … 19 19 20 20 type 21 TPlayerSlot = class 22 DiffUpBtn: TButtonC; 23 DiffDownBtn: TButtonC; 24 MultiBtn: TButtonC; 25 OfferMultiple: Boolean; 26 Rect: TRect; 27 end; 28 29 TPlayerSlots = class(TFPGObjectList<TPlayerSlot>) 30 31 end; 21 32 22 33 { TStartDlg } … … 87 98 Tab: Integer; 88 99 Diff0: Integer; 89 bixDefault: Integer;100 BrainDefault: TBrain; 90 101 nMapLandTiles: Integer; 91 102 nMapStartPositions: Integer; … … 94 105 { last turn of selected former game } 95 106 SlotAvailable: Integer; 96 bixPopup: Integer; { brain concerned by brain context menu }107 PlayerPopupIndex: Integer; { brain concerned by brain context menu } 97 108 ListIndex: array [0 .. 3] of integer; 98 109 MapFileName: string; … … 101 112 MiniColors: array [0 .. 11, 0 .. 1] of TColor; 102 113 // BookDate: string; 103 DiffUpBtn: array [0 .. 8] of TButtonC; 104 DiffDownBtn: array [0 .. 8] of TButtonC; 105 MultiBtn: array [6 .. 8] of TButtonC; 114 PlayerSlots: TPlayerSlots; 106 115 MiniMode: (mmNone, mmPicture, mmMultiPlayer); 107 116 ActionsOffered: set of 0 .. nMainActions - 1; 108 117 TurnValid, Tracking: boolean; 109 118 DefaultAI: string; 110 procedure InitPopup(P opupIndex: integer);119 procedure InitPopup(PlayerIndex: Integer); 111 120 procedure PaintInfo; 112 121 procedure ChangePage(NewPage: integer); … … 191 200 pgMain = 6; 192 201 193 OfferMultiple = [6, 7, 8];194 195 202 PlayerAutoDiff: array [1 .. 5] of integer = (1, 1, 2, 2, 3); 196 203 EnemyAutoDiff: array [1 .. 5] of integer = (4, 3, 2, 1, 1); … … 202 209 Location: TPoint; 203 210 AIBrains: TBrains; 204 begin 211 PlayerSlot: TPlayerSlot; 212 begin 213 PlayerSlots := TPlayerSlots.Create; 214 PlayerSlots.Count := nPlOffered; 215 for I := 0 to PlayerSlots.Count - 1 do begin 216 PlayerSlot := TPlayerSlot.Create; 217 PlayerSlot.Rect := Bounds(xBrain[I], YBrain[I], 0, 0); 218 PlayerSlots[I] := PlayerSlot; 219 end; 205 220 LoadConfig; 206 221 … … 210 225 Include(ActionsOffered, maAIDev); 211 226 212 bixDefault := -1;227 BrainDefault := nil; 213 228 for i := Brains.IndexOf(BrainRandom) to Brains.Count - 1 do 214 229 if AnsiCompareFileName(DefaultAI, Brains[i].FileName) = 0 then 215 bixDefault := i;216 if ( bixDefault = Brains.IndexOf(BrainRandom)) and (Brains.GetKindCount(btAI) < 2) then217 bixDefault := -1;218 if ( bixDefault < 0) and (Brains.GetKindCount(btAI) > 0) then230 BrainDefault := Brains[i]; 231 if (BrainDefault = BrainRandom) and (Brains.GetKindCount(btAI) < 2) then 232 BrainDefault := nil; 233 if (not Assigned(BrainDefault)) and (Brains.GetKindCount(btAI) > 0) then 219 234 begin 220 235 AIBrains := TBrains.Create(False); 221 236 Brains.GetByKind(btAI, AIBrains); 222 bixDefault := Brains.IndexOf(Brains[0]);237 BrainDefault := Brains[0]; 223 238 AIBrains.Free; 224 239 end; // default AI not found, use any … … 256 271 QuitBtn.Hint := Phrases.Lookup('STARTCONTROLS', 0); 257 272 ReplayBtn.Hint := Phrases.Lookup('BTN_REPLAY'); 258 for i := 0 to nPlOffered - 1 do 259 begin 260 DiffUpBtn[i] := TButtonC.Create(self); 261 DiffUpBtn[i].Graphic := GrExt[HGrSystem].Data; 262 DiffUpBtn[i].left := xBrain[i] - 18; 263 DiffUpBtn[i].top := yBrain[i] + 39; 264 DiffUpBtn[i].ButtonIndex := 1; 265 DiffUpBtn[i].Parent := self; 266 DiffUpBtn[i].OnClick := DiffBtnClick; 267 DiffDownBtn[i] := TButtonC.Create(self); 268 DiffDownBtn[i].Graphic := GrExt[HGrSystem].Data; 269 DiffDownBtn[i].left := xBrain[i] - 18; 270 DiffDownBtn[i].top := yBrain[i] + 51; 271 DiffDownBtn[i].ButtonIndex := 0; 272 DiffDownBtn[i].Parent := self; 273 DiffDownBtn[i].OnClick := DiffBtnClick; 273 PlayerSlots.Count := nPlOffered; 274 for i := 0 to PlayerSlots.Count - 1 do 275 with PlayerSlots[i] do begin 276 DiffUpBtn := TButtonC.Create(self); 277 DiffUpBtn.Graphic := GrExt[HGrSystem].Data; 278 DiffUpBtn.left := xBrain[i] - 18; 279 DiffUpBtn.top := yBrain[i] + 39; 280 DiffUpBtn.ButtonIndex := 1; 281 DiffUpBtn.Parent := self; 282 DiffUpBtn.OnClick := DiffBtnClick; 283 DiffDownBtn := TButtonC.Create(self); 284 DiffDownBtn.Graphic := GrExt[HGrSystem].Data; 285 DiffDownBtn.left := xBrain[i] - 18; 286 DiffDownBtn.top := yBrain[i] + 51; 287 DiffDownBtn.ButtonIndex := 0; 288 DiffDownBtn.Parent := self; 289 DiffDownBtn.OnClick := DiffBtnClick; 274 290 end; 275 291 for i := 6 to 8 do 276 begin 277 MultiBtn[i] := TButtonC.Create(self); 278 MultiBtn[i].Graphic := GrExt[HGrSystem].Data; 279 MultiBtn[i].left := xBrain[i] - 18; 280 MultiBtn[i].top := yBrain[i]; 281 MultiBtn[i].Parent := self; 282 MultiBtn[i].OnClick := MultiBtnClick; 292 with PlayerSlots[i] do begin 293 MultiBtn := TButtonC.Create(self); 294 MultiBtn.Graphic := GrExt[HGrSystem].Data; 295 MultiBtn.left := xBrain[i] - 18; 296 MultiBtn.top := yBrain[i]; 297 MultiBtn.Parent := self; 298 MultiBtn.OnClick := MultiBtnClick; 299 OfferMultiple := True; 283 300 end; 284 301 … … 344 361 InitButtons; 345 362 346 bixView[0] := Brains.IndexOf(BrainTerm);363 PlayersBrain[0] := BrainTerm; 347 364 SlotAvailable := -1; 348 365 Tab := 2; … … 365 382 FreeAndNil(EmptyPicture); 366 383 FreeAndNil(LogoBuffer); 384 FreeAndNil(PlayerSlots); 367 385 end; 368 386 … … 645 663 if 1 shl i and SlotAvailable <> 0 then 646 664 begin 647 if bixView[i] >= 0then648 FrameImage(Canvas, Brains[bixView[i]].Picture, xBrain[i], yBrain[i],665 if Assigned(PlayersBrain[i]) then 666 FrameImage(Canvas, PlayersBrain[i].Picture, xBrain[i], yBrain[i], 649 667 64, 64, 0, 0, true) 650 668 else 651 669 FrameImage(Canvas, EmptyPicture, xBrain[i], yBrain[i], 64, 64, 652 670 0, 0, true); 653 if Brains[bixView[i]].Kind in [btTerm, btRandom, btAI]then671 if Assigned(PlayersBrain[I]) and (PlayersBrain[i].Kind in [btTerm, btRandom, btAI]) then 654 672 begin 655 673 BitBlt(Canvas.Handle, xBrain[i] - 18, yBrain[i] + 19, 12, 14, … … 658 676 Frame(Canvas, xBrain[i] - 19, yBrain[i] + 18, xBrain[i] - 18 + 12, 659 677 yBrain[i] + (19 + 14), $000000, $000000); 660 RFrame(Canvas, DiffUpBtn[i].left - 1, DiffUpBtn[i].top - 1,661 DiffUpBtn[i].left + 12, DiffUpBtn[i].top + 24,678 RFrame(Canvas, PlayerSlots[i].DiffUpBtn.left - 1, PlayerSlots[i].DiffUpBtn.top - 1, 679 PlayerSlots[i].DiffUpBtn.left + 12, PlayerSlots[i].DiffUpBtn.top + 24, 662 680 MainTexture.clBevelShade, MainTexture.clBevelLight); 663 681 with Canvas do … … 668 686 Brush.Style := bsClear; 669 687 end; 670 if i inOfferMultiple then688 if PlayerSlots[I].OfferMultiple then 671 689 begin 672 RFrame(Canvas, MultiBtn[i].left - 1, MultiBtn[i].top - 1,673 MultiBtn[i].left + 12, MultiBtn[i].top + 12,690 RFrame(Canvas, PlayerSlots[I].MultiBtn.left - 1, PlayerSlots[I].MultiBtn.top - 1, 691 PlayerSlots[I].MultiBtn.left + 12, PlayerSlots[I].MultiBtn.top + 12, 674 692 MainTexture.clBevelShade, MainTexture.clBevelLight); 675 693 BitBlt(Canvas.Handle, xBrain[i] - 31, yBrain[i], 13, 12, … … 677 695 end 678 696 end; 679 if bixView[i] >= 0then697 if Assigned(PlayersBrain[i]) then 680 698 begin 681 DiffUpBtn[i].Hint := Format(Phrases.Lookup('STARTCONTROLS', 9),682 [ Brains[bixView[i]].Name]);683 DiffDownBtn[i].Hint := DiffUpBtn[i].Hint;699 PlayerSlots[i].DiffUpBtn.Hint := Format(Phrases.Lookup('STARTCONTROLS', 9), 700 [PlayersBrain[i].Name]); 701 PlayerSlots[i].DiffDownBtn.Hint := PlayerSlots[i].DiffUpBtn.Hint; 684 702 end 685 703 end; … … 706 724 64, 0, 0, false) 707 725 else 708 FrameImage(Canvas, Brain s[bixDefault].Picture, xDefault, yDefault, 64, 64,726 FrameImage(Canvas, BrainDefault.Picture, xDefault, yDefault, 64, 64, 709 727 0, 0, true); 710 728 DLine(Canvas, 56, 272, y0Mini + 61 + 19, MainTexture.clBevelLight, … … 901 919 902 920 pgStartRandom, pgStartMap: 903 if bixView[0] >= 0then921 if Assigned(PlayersBrain[0]) then 904 922 begin 905 923 if (Page = pgStartMap) and (nMapStartPositions = 0) and (AutoDiff > 0) … … 917 935 else GameCount := 0; 918 936 919 if (AutoDiff < 0) and ( Brains[bixView[0]].Kind = btNoTerm) then937 if (AutoDiff < 0) and (PlayersBrain[0].Kind = btNoTerm) then 920 938 FileName := 'Round' + IntToStr(GetProcessID()) 921 939 else begin … … 932 950 if AutoDiff < 0 then 933 951 for i := 0 to nPlOffered - 1 do begin 934 if bixView[i] = -1then952 if not Assigned(PlayersBrain[i]) then 935 953 Reg.WriteString('Control' + IntToStr(i), '') 936 954 else Reg.WriteString('Control' + IntToStr(i), 937 Brains[bixView[i]].FileName);955 PlayersBrain[i].FileName); 938 956 WriteInteger('Diff' + IntToStr(i), Difficulty[i]); 939 957 end; … … 944 962 if AutoDiff > 0 then 945 963 begin 946 WriteString('DefaultAI', Brain s[bixDefault].FileName);964 WriteString('DefaultAI', BrainDefault.FileName); 947 965 SlotAvailable := 0; // bixView will be invalid hereafter 948 bixView[0] := Brains.IndexOf(BrainTerm);966 PlayersBrain[0] := BrainTerm; 949 967 Difficulty[0] := PlayerAutoDiff[AutoDiff]; 950 968 for i := 1 to nPl - 1 do 951 969 if (Page = pgStartRandom) and (i <= AutoEnemies) or 952 970 (Page = pgStartMap) and (i < nMapStartPositions) then begin 953 if AutoDiff = 1 then bixView[i] := Brains.IndexOf(BrainBeginner)954 else bixView[i] := bixDefault;971 if AutoDiff = 1 then PlayersBrain[i] := BrainBeginner 972 else PlayersBrain[i] := BrainDefault; 955 973 Difficulty[i] := EnemyAutoDiff[AutoDiff]; 956 end else bixView[i] := -1;974 end else PlayersBrain[i] := nil; 957 975 end else begin 958 976 for i := 6 to 8 do 959 if ( Brains[bixView[0]].Kind <> btNoTerm) and (MultiControl and (1 shl i) <> 0)977 if (PlayersBrain[0].Kind <> btNoTerm) and (MultiControl and (1 shl i) <> 0) 960 978 then begin 961 bixView[i + 3] := bixView[i];979 PlayersBrain[i + 3] := PlayersBrain[i]; 962 980 Difficulty[i + 3] := Difficulty[i]; 963 bixView[i + 6] := bixView[i];981 PlayersBrain[i + 6] := PlayersBrain[i]; 964 982 Difficulty[i + 6] := Difficulty[i]; 965 983 end else begin 966 bixView[i + 3] := -1;967 bixView[i + 6] := -1;984 PlayersBrain[i + 3] := nil; 985 PlayersBrain[i + 6] := nil; 968 986 end 969 987 end; … … 1233 1251 begin 1234 1252 // Play('BUTTON_UP'); 1235 if bixPopup< 0 then1253 if PlayerPopupIndex < 0 then 1236 1254 begin // change default AI 1237 bixDefault := TMenuItem(Sender).Tag;1255 BrainDefault := Brains[TMenuItem(Sender).Tag]; 1238 1256 SmartInvalidate(xDefault, yDefault, xDefault + 64, yDefault + 64); 1239 1257 end 1240 1258 else 1241 1259 begin 1242 Brains[bixView[bixPopup]].Flags := Brains[bixView[bixPopup]].Flags and 1243 not fUsed; 1244 bixView[bixPopup] := TMenuItem(Sender).Tag; 1245 DiffUpBtn[bixPopup].Visible := Brains[bixView[bixPopup]].Kind in [btTerm, btRandom, btAI]; 1246 DiffDownBtn[bixPopup].Visible := Brains[bixView[bixPopup]].Kind in [btTerm, btRandom, btAI]; 1247 if bixPopup in OfferMultiple then 1248 begin 1249 MultiBtn[bixPopup].Visible := Brains[bixView[bixPopup]].Kind in [btTerm, btRandom, btAI]; 1250 MultiBtn[bixPopup].ButtonIndex := 2 + (MultiControl shr bixPopup) and 1; 1260 if Assigned(PlayersBrain[PlayerPopupIndex]) then 1261 PlayersBrain[PlayerPopupIndex].Flags := PlayersBrain[PlayerPopupIndex].Flags and not fUsed; 1262 if TMenuItem(Sender).Tag = -1 then begin 1263 PlayersBrain[PlayerPopupIndex] := nil; 1264 PlayerSlots[PlayerPopupIndex].DiffUpBtn.Visible := False; 1265 PlayerSlots[PlayerPopupIndex].DiffDownBtn.Visible := False; 1266 if PlayerSlots[PlayerPopupIndex].OfferMultiple then begin 1267 PlayerSlots[PlayerPopupIndex].MultiBtn.Visible := False; 1268 PlayerSlots[PlayerPopupIndex].MultiBtn.ButtonIndex := 2 + (MultiControl shr PlayerPopupIndex) and 1; 1269 end; 1270 MultiControl := MultiControl and not (1 shl PlayerPopupIndex); 1271 end else begin 1272 PlayersBrain[PlayerPopupIndex] := Brains[TMenuItem(Sender).Tag]; 1273 PlayerSlots[PlayerPopupIndex].DiffUpBtn.Visible := PlayersBrain[PlayerPopupIndex].Kind in [btTerm, btRandom, btAI]; 1274 PlayerSlots[PlayerPopupIndex].DiffDownBtn.Visible := PlayersBrain[PlayerPopupIndex].Kind in [btTerm, btRandom, btAI]; 1275 if PlayerSlots[PlayerPopupIndex].OfferMultiple then begin 1276 PlayerSlots[PlayerPopupIndex].MultiBtn.Visible := PlayersBrain[PlayerPopupIndex].Kind in [btTerm, btRandom, btAI]; 1277 PlayerSlots[PlayerPopupIndex].MultiBtn.ButtonIndex := 2 + (MultiControl shr PlayerPopupIndex) and 1; 1278 end; 1279 PlayersBrain[PlayerPopupIndex].Flags := PlayersBrain[PlayerPopupIndex].Flags or fUsed; 1280 if PlayersBrain[PlayerPopupIndex].Kind in [btNoTerm, btSuperVirtual] then 1281 Difficulty[PlayerPopupIndex] := 0 { supervisor } 1282 else 1283 Difficulty[PlayerPopupIndex] := 2; 1284 if (Page = pgStartRandom) and (PlayerSlots[PlayerPopupIndex].OfferMultiple) and 1285 (not Assigned(PlayersBrain[PlayerPopupIndex])) then 1286 MultiControl := MultiControl and not (1 shl PlayerPopupIndex); 1287 if (PlayerPopupIndex = 0) and (MapFileName <> '') then 1288 ChangePage(Page); 1289 if PlayersBrain[PlayerPopupIndex].Kind = btNoTerm then 1290 begin // turn all local players off 1291 for I := 1 to PlayerSlots.Count - 1 do 1292 if PlayersBrain[I].Kind = btTerm then begin 1293 PlayersBrain[i] := nil; 1294 PlayerSlots[i].DiffUpBtn.Visible := false; 1295 PlayerSlots[i].DiffUpBtn.Tag := 0; 1296 PlayerSlots[i].DiffDownBtn.Visible := false; 1297 PlayerSlots[i].DiffDownBtn.Tag := 0; 1298 if PlayerSlots[i].OfferMultiple then begin 1299 PlayerSlots[i].MultiBtn.Visible := false; 1300 PlayerSlots[i].MultiBtn.Tag := 0; 1301 end; 1302 SmartInvalidate(xBrain[i] - 31, yBrain[i] - 1, xBrain[i] + 64, 1303 PlayerSlots[i].DiffUpBtn.top + 25); 1304 end; 1305 BrainTerm.Flags := BrainTerm.Flags and not fUsed; 1306 end; 1251 1307 end; 1252 Brains[bixView[bixPopup]].Flags := Brains[bixView[bixPopup]].Flags or fUsed; 1253 if Brains[bixView[bixPopup]].Kind in [btNoTerm, btSuperVirtual] then 1254 Difficulty[bixPopup] := 0 { supervisor } 1255 else 1256 Difficulty[bixPopup] := 2; 1257 if (Page = pgStartRandom) and (bixPopup in OfferMultiple) and 1258 (bixView[bixPopup] < 0) then 1259 MultiControl := MultiControl and not(1 shl bixPopup); 1260 if (bixPopup = 0) and (MapFileName <> '') then 1261 ChangePage(Page); 1262 if Brains[bixView[bixPopup]].Kind = btNoTerm then 1263 begin // turn all local players off 1264 for i := 1 to nPlOffered - 1 do 1265 if Brains[bixView[i]].Kind = btTerm then 1266 begin 1267 bixView[i] := -1; 1268 DiffUpBtn[i].Visible := false; 1269 DiffUpBtn[i].Tag := 0; 1270 DiffDownBtn[i].Visible := false; 1271 DiffDownBtn[i].Tag := 0; 1272 if i in OfferMultiple then 1273 begin 1274 MultiBtn[i].Visible := false; 1275 MultiBtn[i].Tag := 0; 1276 end; 1277 SmartInvalidate(xBrain[i] - 31, yBrain[i] - 1, xBrain[i] + 64, 1278 DiffUpBtn[i].top + 25); 1279 end; 1280 BrainTerm.Flags := BrainTerm.Flags and not fUsed; 1281 end; 1282 SmartInvalidate(xBrain[bixPopup] - 31, yBrain[bixPopup] - 1, 1283 xBrain[bixPopup] + 64, DiffUpBtn[bixPopup].top + 25); 1284 end 1285 end; 1286 1287 procedure TStartDlg.InitPopup(PopupIndex: integer); 1288 var 1289 i, FixedLines: integer; 1290 m: TMenuItem; 1308 SmartInvalidate(xBrain[PlayerPopupIndex] - 31, yBrain[PlayerPopupIndex] - 1, 1309 xBrain[PlayerPopupIndex] + 64, PlayerSlots[PlayerPopupIndex].DiffUpBtn.top + 25); 1310 end 1311 end; 1312 1313 procedure TStartDlg.InitPopup(PlayerIndex: Integer); 1314 var 1315 I: Integer; 1316 FixedLines: integer; 1317 MenuItem: TMenuItem; 1291 1318 AIBrains: TBrains; 1292 1319 1293 procedure OfferBrain( Index: integer);1320 procedure OfferBrain(Brain: TBrain); 1294 1321 var 1295 j: integer; 1296 begin 1297 m := TMenuItem.Create(PopupMenu1); 1298 if Index < 0 then 1299 m.Caption := Phrases.Lookup('NOMOD') 1300 else 1301 m.Caption := Brains[Index].Name; 1302 m.Tag := Index; 1303 m.OnClick := BrainClick; 1304 j := FixedLines; 1305 while (j < PopupMenu1.Items.Count) and 1306 (StrIComp(pchar(m.Caption), pchar(PopupMenu1.Items[j].Caption)) > 0) do 1307 inc(j); 1308 m.RadioItem := true; 1309 if bixPopup < 0 then 1310 m.Checked := bixDefault = Index 1311 else 1312 m.Checked := bixView[bixPopup] = Index; 1313 PopupMenu1.Items.Insert(j, m); 1314 end; 1315 1316 begin 1317 bixPopup := PopupIndex; 1322 J: Integer; 1323 begin 1324 MenuItem := TMenuItem.Create(PopupMenu1); 1325 if not Assigned(Brain) then MenuItem.Caption := Phrases.Lookup('NOMOD') 1326 else MenuItem.Caption := Brain.Name; 1327 MenuItem.Tag := Brains.IndexOf(Brain); 1328 MenuItem.OnClick := BrainClick; 1329 J := FixedLines; 1330 while (J < PopupMenu1.Items.Count) and 1331 (StrIComp(pchar(MenuItem.Caption), pchar(PopupMenu1.Items[J].Caption)) > 0) do 1332 Inc(J); 1333 MenuItem.RadioItem := True; 1334 if (PlayerPopupIndex < 0) then MenuItem.Checked := BrainDefault = Brain 1335 else MenuItem.Checked := PlayersBrain[PlayerPopupIndex] = Brain; 1336 PopupMenu1.Items.Insert(J, MenuItem); 1337 end; 1338 1339 begin 1340 PlayerPopupIndex := PlayerIndex; 1318 1341 EmptyMenu(PopupMenu1.Items); 1319 if bixPopup < 0 then 1320 begin // select default AI 1342 if PlayerPopupIndex < 0 then begin // select default AI 1321 1343 FixedLines := 0; 1322 if Brains.GetKindCount(btAI) >= 2 then 1323 begin 1324 OfferBrain(Brains.IndexOf(BrainRandom)); 1325 inc(FixedLines) 1344 if Brains.GetKindCount(btAI) >= 2 then begin 1345 OfferBrain(BrainRandom); 1346 Inc(FixedLines); 1326 1347 end; 1327 1348 AIBrains := TBrains.Create(False); 1328 1349 Brains.GetByKind(btAI, AIBrains); 1329 for i:= 0 to AIBrains.Count - 1 do // offer available AIs1330 if AIBrains[ i].Flags and fMultiple <> 0 then1331 OfferBrain( Brains.IndexOf(AIBrains[i]));1350 for I := 0 to AIBrains.Count - 1 do // offer available AIs 1351 if AIBrains[I].Flags and fMultiple <> 0 then 1352 OfferBrain(AIBrains[I]); 1332 1353 AIBrains.Free; 1333 end 1334 else 1335 begin 1354 end else begin 1336 1355 FixedLines := 0; 1337 if bixPopup > 0 then 1338 begin 1339 OfferBrain(-1); 1340 inc(FixedLines); 1356 if PlayerPopupIndex > 0 then begin 1357 OfferBrain(nil); 1358 Inc(FixedLines); 1341 1359 end; 1342 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 1344 begin 1345 OfferBrain(i); 1346 inc(FixedLines); 1347 end; 1348 if bixPopup > 0 then 1349 begin 1350 m := TMenuItem.Create(PopupMenu1); 1351 m.Caption := '-'; 1352 PopupMenu1.Items.Add(m); 1353 inc(FixedLines); 1354 if Brains.GetKindCount(btAI) >= 2 then 1355 begin 1356 OfferBrain(Brains.IndexOf(BrainRandom)); 1357 inc(FixedLines); 1360 for I := Brains.IndexOf(BrainTerm) downto 0 do // offer game interfaces 1361 if (PlayerPopupIndex = 0) or (Brains[i].Kind = btTerm) and 1362 (PlayersBrain[0].Kind <> btNoTerm) then begin 1363 OfferBrain(Brains[I]); 1364 Inc(FixedLines); 1365 end; 1366 if PlayerPopupIndex > 0 then begin 1367 MenuItem := TMenuItem.Create(PopupMenu1); 1368 MenuItem.Caption := '-'; 1369 PopupMenu1.Items.Add(MenuItem); 1370 Inc(FixedLines); 1371 if Brains.GetKindCount(btAI) >= 2 then begin 1372 OfferBrain(BrainRandom); 1373 Inc(FixedLines); 1358 1374 end; 1359 1375 AIBrains := TBrains.Create(False); 1360 1376 Brains.GetByKind(btAI, AIBrains); 1361 for i:= 0 to AIBrains.Count - 1 do // offer available AIs1362 if (AIBrains[ i].Flags and fMultiple <> 0) or (AIBrains[i].Flags and fUsed = 0)1363 or ( i = bixView[bixPopup]) then1364 OfferBrain( Brains.IndexOf(AIBrains[i]));1377 for I := 0 to AIBrains.Count - 1 do // offer available AIs 1378 if (AIBrains[I].Flags and fMultiple <> 0) or (AIBrains[I].Flags and fUsed = 0) 1379 or (Brains[I] = PlayersBrain[PlayerPopupIndex]) then 1380 OfferBrain(AIBrains[i]); 1365 1381 AIBrains.Free; 1366 1382 end; 1367 end 1383 end; 1368 1384 end; 1369 1385 … … 1426 1442 if i = 0 then 1427 1443 begin 1428 bixView[0] := Brains.IndexOf(BrainSuperVirtual);1444 PlayersBrain[0] := BrainSuperVirtual; 1429 1445 Difficulty[0] := 0 1430 1446 end; 1431 if Brains[bixView[0]].Kind in [btNoTerm, btSuperVirtual] then1447 if PlayersBrain[0].Kind in [btNoTerm, btSuperVirtual] then 1432 1448 inc(i); 1433 1449 if i > nPl then … … 1446 1462 OpenKey(AppRegistryKey + '\AI', True); 1447 1463 for p1 := 0 to nPlOffered - 1 do begin 1448 bixView[p1] := -1;1464 PlayersBrain[p1] := nil; 1449 1465 s := ReadString('Control' + IntToStr(p1)); 1450 1466 Difficulty[p1] := ReadInteger('Diff' + IntToStr(p1)); … … 1452 1468 for j := 0 to Brains.Count - 1 do 1453 1469 if AnsiCompareFileName(s, Brains[j].FileName) = 0 then 1454 bixView[p1] := j;1470 PlayersBrain[p1] := Brains[j]; 1455 1471 end; 1456 1472 MultiControl := Reg.ReadInteger('MultiControl'); … … 1463 1479 if 1 shl p1 and InitAlive[i] <> 0 then 1464 1480 begin 1465 bixView[p1] := bixDefault;1481 PlayersBrain[p1] := BrainDefault; 1466 1482 Difficulty[p1] := 2; 1467 1483 end 1468 1484 else 1469 bixView[p1] := -1;1485 PlayersBrain[p1] := nil; 1470 1486 SlotAvailable := InitAlive[i]; 1471 1487 for i := 0 to nPlOffered - 1 do 1472 if (AutoDiff < 0) and (Brains[bixView[i]].Kind in [btTerm, btRandom, btAI]) then 1488 if (AutoDiff < 0) and Assigned(PlayersBrain[i]) and 1489 (PlayersBrain[i].Kind in [btTerm, btRandom, btAI]) then 1473 1490 begin 1474 DiffUpBtn[i].Tag := 768;1475 DiffDownBtn[i].Tag := 768;1491 PlayerSlots[i].DiffUpBtn.Tag := 768; 1492 PlayerSlots[i].DiffDownBtn.Tag := 768; 1476 1493 end 1477 1494 else 1478 1495 begin 1479 DiffUpBtn[i].Tag := 0;1480 DiffDownBtn[i].Tag := 0;1496 PlayerSlots[i].DiffUpBtn.Tag := 0; 1497 PlayerSlots[i].DiffDownBtn.Tag := 0; 1481 1498 end; 1482 1499 for i := 6 to 8 do 1483 if (AutoDiff < 0) and (Brains[bixView[i]].Kind in [btTerm, btRandom, btAI]) then 1500 if (AutoDiff < 0) and Assigned(PlayersBrain[i]) and 1501 (PlayersBrain[i].Kind in [btTerm, btRandom, btAI]) then 1484 1502 begin 1485 MultiBtn[i].Tag := 768;1486 MultiBtn[i].ButtonIndex := 2 + (MultiControl shr i) and 1;1487 MultiBtn[i].Enabled := Page = pgStartRandom1503 PlayerSlots[i].MultiBtn.Tag := 768; 1504 PlayerSlots[i].MultiBtn.ButtonIndex := 2 + (MultiControl shr i) and 1; 1505 PlayerSlots[i].MultiBtn.Enabled := Page = pgStartRandom 1488 1506 end 1489 1507 else 1490 MultiBtn[i].Tag := 0;1508 PlayerSlots[i].MultiBtn.Tag := 0; 1491 1509 if (AutoDiff > 0) and (Page <> pgStartMap) then 1492 1510 begin … … 1508 1526 AutoDiffUpBtn.Tag := 0; 1509 1527 AutoDiffDownBtn.Tag := 0; 1510 end 1528 end; 1511 1529 end; 1512 1530 … … 1859 1877 begin 1860 1878 for i := 0 to nPlOffered - 1 do 1861 if (Sender = DiffUpBtn[i]) and (Difficulty[i] < 3) or1862 (Sender = DiffDownBtn[i]) and (Difficulty[i] > 1) then1879 if (Sender = PlayerSlots[i].DiffUpBtn) and (Difficulty[i] < 3) or 1880 (Sender = PlayerSlots[i].DiffDownBtn) and (Difficulty[i] > 1) then 1863 1881 begin 1864 if Sender = DiffUpBtn[i]then1882 if Sender = PlayerSlots[i].DiffUpBtn then 1865 1883 inc(Difficulty[i]) 1866 1884 else … … 1876 1894 begin 1877 1895 for i := 6 to 8 do 1878 if Sender = MultiBtn[i]then1896 if Sender = PlayerSlots[i].MultiBtn then 1879 1897 begin 1880 1898 MultiControl := MultiControl xor (1 shl i);
Note:
See TracChangeset
for help on using the changeset viewer.