Changeset 145
- Timestamp:
- May 13, 2018, 3:18:55 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GameServer.pas
r144 r145 87 87 var 88 88 // PARAMETERS 89 PlayersBrain: TBrains; { brain indexof the players }89 PlayersBrain: TBrains; { brain of the players } 90 90 Difficulty: array [0 .. nPl - 1] of integer absolute Database.Difficulty; 91 91 { difficulty } … … 146 146 LastOffer: TOffer; 147 147 CCData: array [0 .. 14] of integer; 148 bix: TBrains; { brain of the players } 148 149 DevModelTurn, { turn of last call to sResetModel } 149 bix, { brain index of the players }150 150 OriginalDataVersion: array [0 .. nPl - 1] of integer; 151 151 SavedTiles { , SavedResourceWeights } : array [0 .. ncmax - 1] of Cardinal; … … 179 179 HandoverStack[nHandoverStack + 1] := Command; 180 180 inc(nHandoverStack, 2); 181 Brains[bix[p]].Client(Command, p, Data);181 bix[p].Client(Command, p, Data); 182 182 dec(nHandoverStack, 2); 183 183 {$ELSE} … … 193 193 procedure CallClient(bix, Command: integer; var Data); 194 194 begin 195 if ((Mode <> moMovie) or (bix = GameServer.bix[0])) then195 if ((Mode <> moMovie) or (bix = Brains.IndexOf(GameServer.bix[0]))) then 196 196 begin 197 197 {$IFOPT O-} … … 224 224 for I := 0 to nPl - 1 do 225 225 PlayersBrain[I] := nil; 226 227 bix := TBrains.Create(False); 228 bix.Count := nPl; 229 for I := 0 to nPl - 1 do 230 bix[I] := nil; 226 231 227 232 { get available brains } … … 282 287 end; 283 288 PlayersBrain.Free; 289 bix.Free; 284 290 Brains.Free; 285 291 end; … … 313 319 procedure PutMessage(Level: integer; Text: string); 314 320 begin 315 Brains[bix[0]].Client(cDebugMessage, Level, pchar(Text)^);321 bix[0].Client(cDebugMessage, Level, pchar(Text)^); 316 322 end; 317 323 … … 348 354 LastClientTime := T; 349 355 PutMessage(1 shl 16 + 2, Format('CLIENT: calling %d (%s)', 350 [CCPlayer, Brains[bix[CCPlayer]].Name]));356 [CCPlayer, bix[CCPlayer].Name])); 351 357 if CCCommand = cTurn then 352 358 for p := 0 to nPl - 1 do … … 357 363 CCPlayer := -1; 358 364 CallPlayer(CCCommand, p, CCData); 359 if (Mode = moPlaying) and ( Brains[bix[p]].Flags and aiThreaded = 0) and365 if (Mode = moPlaying) and (bix[p].Flags and aiThreaded = 0) and 360 366 (CCPlayer < 0) then 361 367 begin … … 378 384 move(GShip, RW[p].Ship, SizeOf(GShip)); 379 385 for p1 := 0 to nPl - 1 do 380 if (p1 <> p) and (bix[p1] >= 0) and (Difficulty[p1] > 0) then386 if (p1 <> p) and Assigned(bix[p1]) and (Difficulty[p1] > 0) then 381 387 RW[p].EnemyReport[p1].Credibility := RW[p1].Credibility; 382 388 for p1 := 0 to nPl - 1 do … … 435 441 end; 436 442 // log data changes 437 if Brains[bix[p]].DataSize > 0 then443 if bix[p].DataSize > 0 then 438 444 begin 439 445 CL.PutDataChanges(sIntDataChange, p, SavedData[p], RW[p].Data, 440 Brains[bix[p]].DataSize);441 move(RW[p].Data^, SavedData[p]^, Brains[bix[p]].DataSize * 4);446 bix[p].DataSize); 447 move(RW[p].Data^, SavedData[p]^, bix[p].DataSize * 4); 442 448 end 443 449 end; … … 463 469 with RW[p].EnemyCity[ix] do 464 470 SavedStatus := Status; 465 if Brains[bix[p]].DataSize > 0 then466 move(RW[p].Data^, SavedData[p]^, Brains[bix[p]].DataSize * 4);471 if bix[p].DataSize > 0 then 472 move(RW[p].Data^, SavedData[p]^, bix[p].DataSize * 4); 467 473 end; 468 474 end; … … 493 499 result := true; 494 500 if RW[p].Data <> nil then 495 for ix := 0 to Brains[bix[p]].DataSize - 1 do501 for ix := 0 to bix[p].DataSize - 1 do 496 502 if PDWortList(SavedData[p])[ix] <> PDWortList(RW[p].Data)[ix] then 497 503 result := true 498 504 end; 499 505 500 procedure InitBrain(bix: integer);506 procedure InitBrain(bix: TBrain); 501 507 var 502 508 InitModuleData: TInitModuleData; 503 509 begin 504 assert( Brains[bix].Kind <> btSuperVirtual);505 with Brains[bix]do begin510 assert(bix.Kind <> btSuperVirtual); 511 with bix do begin 506 512 if Initialized then 507 513 exit; 508 514 if Kind = btAI then 509 515 begin { get client function } 510 Notify(ntInitModule + bix);516 Notify(ntInitModule + Brains.IndexOf(bix)); 511 517 if Flags and fDotNet > 0 then 512 518 Client := DotNetClient … … 517 523 begin 518 524 Client := nil; 519 Notify(ntDLLError + bix);525 Notify(ntDLLError + Brains.IndexOf(bix)); 520 526 end 521 527 else … … 523 529 Client := GetProcAddress(hm, 'client'); 524 530 if @Client = nil then 525 Notify(ntClientError + bix);531 Notify(ntClientError + Brains.IndexOf(bix)); 526 532 end 527 533 end … … 534 540 InitModuleData.DataSize := 0; 535 541 InitModuleData.Flags := 0; 536 CallClient( bix, cInitModule, InitModuleData);542 CallClient(Brains.IndexOf(bix), cInitModule, InitModuleData); 537 543 DataVersion := InitModuleData.DataVersion; 538 544 DataSize := (InitModuleData.DataSize + 3) div 4; … … 620 626 nLocal := 0; 621 627 for i := 0 to nPl - 1 do 622 if (bix[i] <> -1) and (Brains[bix[i]].Kind = btTerm) then628 if Assigned(bix[i]) and (bix[i].Kind = btTerm) then 623 629 inc(nLocal); 624 630 if Difficulty[0] = 0 then … … 664 670 LogFile.write(SaveMap, ((MapSize - 1) div 4 + 1) * 4); 665 671 for i := 0 to nPl - 1 do 666 if bix[i] < 0then672 if not Assigned(bix[i]) then 667 673 LogFile.write(zero, 4) 668 674 else 669 675 begin 670 676 if PlayersBrain[i].Kind in [btRandom, btAI] then 671 s := Brains[bix[i]].FileName677 s := bix[i].FileName 672 678 else 673 679 s := PlayersBrain[i].FileName; … … 704 710 for p1 := 0 to nPl - 1 do begin 705 711 if Assigned(PlayersBrain[p1]) and (PlayersBrain[p1].Kind = btSuperVirtual) then 706 bix[p1] := Brain s.IndexOf(BrainTerm)// supervisor and local human use same module712 bix[p1] := BrainTerm // supervisor and local human use same module 707 713 else if Assigned(PlayersBrain[p1]) and (PlayersBrain[p1].Kind = btRandom) then 708 714 if Brains.GetKindCount(btAI) = 0 then 709 bix[p1] := -1715 bix[p1] := nil 710 716 else begin 711 717 AIBrains := TBrains.Create(False); 712 718 Brains.GetByKind(btAI, AIBrains); 713 bix[p1] := Brains.IndexOf(AIBrains[DelphiRandom(AIBrains.Count)]);719 bix[p1] := AIBrains[DelphiRandom(AIBrains.Count)]; 714 720 AIBrains.Free; 715 721 end 716 722 else 717 bix[p1] := Brains.IndexOf(PlayersBrain[p1]);723 bix[p1] := PlayersBrain[p1]; 718 724 if not Assigned(PlayersBrain[p1]) then 719 725 Difficulty[p1] := -1; 720 726 end; 721 727 722 if Brains[bix[0]].Kind <> btNoTerm then728 if bix[0].Kind <> btNoTerm then 723 729 Notify(ntInitLocalHuman); 724 730 BrainUsed := []; 725 731 for p := 0 to nPl - 1 do 726 if (bix[p] >= 0) and ((Mode <> moMovie) or (p = 0)) then732 if Assigned(bix[p]) and ((Mode <> moMovie) or (p = 0)) then 727 733 begin { initiate selected control module } 728 AIInfo[p] := Brains[bix[p]].Name + #0;734 AIInfo[p] := bix[p].Name + #0; 729 735 InitBrain(bix[p]); 730 736 if Mode = moPlaying then 731 737 begin // new game, this data version is original 732 OriginalDataVersion[p] := Brains[bix[p]].DataVersion;738 OriginalDataVersion[p] := bix[p].DataVersion; 733 739 ProcessClientData[p] := true; 734 740 end 735 741 else // loading game, compare with data version read from file 736 742 ProcessClientData[p] := ProcessClientData[p] and 737 (OriginalDataVersion[p] = Brains[bix[p]].DataVersion);738 if @ Brains[bix[p]].Client = nil then // client function not found739 if Brains[bix[0]].Kind = btNoTerm then740 bix[p] := -1743 (OriginalDataVersion[p] = bix[p].DataVersion); 744 if @bix[p].Client = nil then // client function not found 745 if bix[0].Kind = btNoTerm then 746 bix[p] := nil 741 747 else 742 748 begin 743 bix[p] := Brain s.IndexOf(BrainTerm);749 bix[p] := BrainTerm; 744 750 OriginalDataVersion[p] := -1; 745 751 ProcessClientData[p] := false; 746 752 end; 747 if bix[p] >= 0then748 include(BrainUsed, bix[p])753 if Assigned(bix[p]) then 754 include(BrainUsed, Brains.IndexOf(bix[p])); 749 755 end; 750 756 … … 758 764 GAI := 0; 759 765 for p1 := 0 to nPl - 1 do 760 if bix[p1] >= 0then766 if Assigned(bix[p1]) then 761 767 begin 762 768 if Mode <> moMovie then 763 769 inc(GWatching, 1 shl p1); 764 if Brains[bix[p1]].Kind = btAI then770 if bix[p1].Kind = btAI then 765 771 inc(GAI, 1 shl p1); 766 772 if Difficulty[p1] > 0 then … … 769 775 inc(nAlive); 770 776 end; 771 ServerVersion[p1] := Brains[bix[p1]].ServerVersion;777 ServerVersion[p1] := bix[p1].ServerVersion; 772 778 end; 773 WinOnAlone := ( Brains[bix[0]].Kind = btNoTerm) and (nAlive > 1);779 WinOnAlone := (bix[0].Kind = btNoTerm) and (nAlive > 1); 774 780 GWinner := 0; 775 781 GColdWarStart := -ColdWarTurns - 1; … … 806 812 OracleIncome := 0; 807 813 808 if Brains[bix[p]].DataSize > 0 then814 if bix[p].DataSize > 0 then 809 815 begin 810 GetMem(SavedData[p], Brains[bix[p]].DataSize * 4);811 GetMem(Data, Brains[bix[p]].DataSize * 4);812 FillChar(SavedData[p]^, Brains[bix[p]].DataSize * 4, 0);813 FillChar(Data^, Brains[bix[p]].DataSize * 4, 0);816 GetMem(SavedData[p], bix[p].DataSize * 4); 817 GetMem(Data, bix[p].DataSize * 4); 818 FillChar(SavedData[p]^, bix[p].DataSize * 4, 0); 819 FillChar(Data^, bix[p].DataSize * 4, 0); 814 820 end 815 821 else … … 828 834 for i := 0 to nStat - 1 do 829 835 GetMem(Stat[i, p], 4 * (MaxTurn + 1)); 830 if Brains[bix[p]].Flags and fDotNet <> 0 then836 if bix[p].Flags and fDotNet <> 0 then 831 837 begin 832 838 GetMem(RW[p].DefaultDebugMap, MapSize * 4); … … 854 860 Human := 0; 855 861 for p1 := 0 to nPl - 1 do 856 if Brains[bix[p1]].Kind = btTerm then862 if bix[p1].Kind = btTerm then 857 863 inc(Human, 1 shl p1); 858 864 InitMapGame(Human); … … 865 871 866 872 pTurn := -1; 867 if Brains[bix[0]].Kind <> btNoTerm then873 if bix[0].Kind <> btNoTerm then 868 874 Notify(ntInitLocalHuman); 869 875 Game.lx := lx; … … 885 891 for p := 0 to nPl - 1 do 886 892 begin 887 if bix[p]= i then893 if Brains.IndexOf(bix[p]) = i then 888 894 Game.RO[p] := @RW[p] 889 895 else 890 896 Game.RO[p] := nil; 891 if (Kind = btTerm) and (Difficulty[0] = 0) and (bix[p] >= 0) then897 if (Kind = btTerm) and (Difficulty[0] = 0) and Assigned(bix[p]) then 892 898 Game.SuperVisorRO[p] := @RW[p] 893 899 else … … 930 936 AICredits := AICredits + #0; 931 937 932 if Brains[bix[0]].Kind <> btNoTerm then938 if bix[0].Kind <> btNoTerm then 933 939 begin 934 940 // uni ai? 935 941 bixUni := -1; 936 942 for p1 := 0 to nPl - 1 do 937 if (bix[p1] <> - 1) and (Brains[bix[p1]].Kind = btAI) then943 if Assigned(bix[p1]) and (bix[p1].Kind = btAI) then 938 944 if bixUni = -1 then 939 bixUni := bix[p1]940 else if bixUni <> bix[p1]then945 bixUni := Brains.IndexOf(bix[p1]) 946 else if bixUni <> Brains.IndexOf(bix[p1]) then 941 947 bixUni := -2; 942 948 for p1 := 0 to nPl - 1 do 943 if (bix[p1] <> -1) and (Brains[bix[p1]].Kind = btAI) then949 if Assigned(bix[p1]) and (bix[p1].Kind = btAI) then 944 950 begin 945 951 if bixUni = -2 then 946 NotifyMessage := Brains[bix[p1]].FileName952 NotifyMessage := bix[p1].FileName 947 953 else 948 954 NotifyMessage := ''; … … 968 974 FreeMem(MapField); 969 975 for p1 := 0 to nPl - 1 do 970 if bix[p1] >= 0then976 if Assigned(bix[p1]) then 971 977 begin 972 978 for i := 0 to nStat - 1 do … … 1197 1203 if MovieMode then 1198 1204 begin 1199 Brains[bix[0]].Client(cShowGame, 0, nil^);1205 bix[0].Client(cShowGame, 0, nil^); 1200 1206 Notify(ntBackOff); 1201 1207 end … … 1227 1233 {$IFDEF TEXTLOG}WriteLn(TextLog, '---Turn 0 P0---'); {$ENDIF} 1228 1234 for p1 := 0 to nPl - 1 do 1229 if (bix[p1] >= 0) and ((Mode <> moMovie) or (p1 = 0)) then1235 if Assigned(bix[p1]) and ((Mode <> moMovie) or (p1 = 0)) then 1230 1236 CallPlayer(cReplay, p1, nil^); 1231 1237 BeforeTurn0; … … 1249 1255 {$IFDEF TEXTLOG}LoadPos0 := CL.State.LoadPos; {$ENDIF} 1250 1256 if ProcessClientData[p1] then 1251 CL.GetDataChanges(RW[p1].Data, Brains[bix[p1]].DataSize)1257 CL.GetDataChanges(RW[p1].Data, bix[p1].DataSize) 1252 1258 else 1253 1259 CL.GetDataChanges(nil, 0); … … 1273 1279 begin 1274 1280 Notify(ntBackOn); 1275 Brains[bix[0]].Client(cBreakGame, -1, nil^);1281 bix[0].Client(cBreakGame, -1, nil^); 1276 1282 EndGame; 1277 1283 Notify(ntStartGo); … … 1318 1324 Notify(ntLoadError); 1319 1325 end; 1320 Brains[bix[0]].Client(cShowGame, 0, nil^);1326 bix[0].Client(cShowGame, 0, nil^); 1321 1327 Notify(ntBackOff); 1322 1328 Inform(pTurn); … … 1380 1386 NoLogChanges; 1381 1387 for p := 0 to nPl - 1 do 1382 if bix[p] >= 0then1388 if Assigned(bix[p]) then 1383 1389 CallPlayer(cGetReady, p, nil^); 1384 1390 LogChanges; … … 1389 1395 nLogOpened := -1; 1390 1396 LastEndClientCommand := -1; 1391 Brains[bix[0]].Client(cShowGame, 0, nil^);1397 bix[0].Client(cShowGame, 0, nil^); 1392 1398 Notify(ntBackOff); 1393 1399 Inform(pTurn); … … 1397 1403 procedure DirectHelp(Command: integer); 1398 1404 begin 1399 InitBrain(Brain s.IndexOf(BrainTerm));1405 InitBrain(BrainTerm); 1400 1406 BrainTerm.Client(Command, -1, nil^); 1401 1407 AICredits := #0; … … 1414 1420 MapSize := lx * ly; 1415 1421 LandMass := NewLandMass; 1416 bix[0] := Brain s.IndexOf(BrainTerm);1422 bix[0] := BrainTerm; 1417 1423 Difficulty[0] := 0; 1418 InitBrain(Brain s.IndexOf(BrainTerm));1424 InitBrain(BrainTerm); 1419 1425 1420 1426 DelphiRandomize; … … 1442 1448 DiscoverAll(0, lObserveSuper); 1443 1449 Notify(ntEndInfo); 1444 Brains[bix[0]].Client(cShowGame, 0, nil^);1450 bix[0].Client(cShowGame, 0, nil^); 1445 1451 Notify(ntBackOff); 1446 1452 ChangeClientWhenDone(cEditMap, 0, nil^, 0) … … 1897 1903 then { supervisor - all tiles visible } 1898 1904 begin 1899 if ( Brains[bix[pTurn]].Kind <> btNoTerm) and1905 if (bix[pTurn].Kind <> btNoTerm) and 1900 1906 ((Difficulty[pTurn] > 0) or (Mode > moLoading_Fast)) then 1901 1907 DiscoverAll(pTurn, lObserveSuper) … … 2094 2100 ShowMove.Flags := ShowMove.Flags or umShipLoading; 2095 2101 for p1 := 0 to nPl - 1 do 2096 if (1 shl p1 and GWatching <> 0) and ((p1 <> p) or ( Brains[bix[p1]].Kind = btTerm))2102 if (1 shl p1 and GWatching <> 0) and ((p1 <> p) or (bix[p1].Kind = btTerm)) 2097 2103 then 2098 2104 begin … … 2265 2271 if Mode >= moMovie then { show after-move in interface modules } 2266 2272 for p1 := 0 to nPl - 1 do 2267 if (1 shl p1 and GWatching <> 0) and ((p1 <> p) or ( Brains[bix[p1]].Kind = btTerm))2273 if (1 shl p1 and GWatching <> 0) and ((p1 <> p) or (bix[p1].Kind = btTerm)) 2268 2274 then 2269 2275 begin … … 2373 2379 if Mode >= moMovie then { show attack in interface modules } 2374 2380 for p1 := 0 to nPl - 1 do 2375 if (1 shl p1 and GWatching <> 0) and ((p1 <> p) or ( Brains[bix[p1]].Kind = btTerm))2381 if (1 shl p1 and GWatching <> 0) and ((p1 <> p) or (bix[p1].Kind = btTerm)) 2376 2382 then 2377 2383 begin … … 2535 2541 Lost := Destroyed[p, Owner, mix]; 2536 2542 for p1 := 0 to nPl - 1 do { show after-attack in interface modules } 2537 if (1 shl p1 and GWatching <> 0) and ((p1 <> p) or ( Brains[bix[p1]].Kind = btTerm))2543 if (1 shl p1 and GWatching <> 0) and ((p1 <> p) or (bix[p1].Kind = btTerm)) 2538 2544 then 2539 2545 begin … … 2799 2805 } 2800 2806 sMessage: 2801 Brains[bix[0]].Client(cDebugMessage, Subject, Data);2807 bix[0].Client(cDebugMessage, Subject, Data); 2802 2808 2803 2809 sSetDebugMap: … … 2816 2822 2817 2823 sRefreshDebugMap: 2818 Brains[bix[0]].Client(cRefreshDebugMap, -1, Player);2824 bix[0].Client(cRefreshDebugMap, -1, Player); 2819 2825 2820 2826 sGetChart .. sGetChart + (nStat - 1) shl 4: 2821 if (Subject >= 0) and (Subject < nPl) and (bix[Subject] >= 0) then2827 if (Subject >= 0) and (Subject < nPl) and Assigned(bix[Subject]) then 2822 2828 begin 2823 2829 StopTurn := 0; … … 3113 3119 AllHumansDead := true; 3114 3120 for p1 := 0 to nPl - 1 do 3115 if (1 shl p1 and GAlive <> 0) and ( Brains[bix[p1]].Kind = btTerm) then3121 if (1 shl p1 and GAlive <> 0) and (bix[p1].Kind = btTerm) then 3116 3122 AllHumansDead := false; 3117 3123 if (pDipActive >= 0) // still in negotiation mode … … 3187 3193 if pTurn = 0 then 3188 3194 inc(GTurn); 3189 if (bix[pTurn] >= 0) and ((1 shl pTurn) and GAlive = 0) then3195 if Assigned(bix[pTurn]) and ((1 shl pTurn) and GAlive = 0) then 3190 3196 begin // already made extinct -- continue statistics 3191 3197 Stat[stExplore, pTurn, GTurn] := 0; … … 3230 3236 if Command = sReload then 3231 3237 begin 3232 ok := (Difficulty[0] = 0) and ( Brains[bix[0]].Kind <> btNoTerm) and3238 ok := (Difficulty[0] = 0) and (bix[0].Kind <> btNoTerm) and 3233 3239 (integer(Data) >= 0) and (integer(Data) < GTurn); 3234 3240 for p1 := 1 to nPl - 1 do 3235 if Brains[bix[p1]].Kind = btTerm then3241 if bix[p1].Kind = btTerm then 3236 3242 ok := false; 3237 3243 // allow reload in AI-only games only … … 3461 3467 pTarget := p1; 3462 3468 Action := Command; 3463 Brains[bix[0]].Client(cShowNego, 1 shl 16 + 3, ShowNegoData);3469 bix[0].Client(cShowNego, 1 shl 16 + 3, ShowNegoData); 3464 3470 end; 3465 3471 pDipActive := p1; … … 3562 3568 Action := Command; 3563 3569 Offer := TOffer(Data); 3564 Brains[bix[0]].Client(cShowNego, 1 shl 16 + 3, ShowNegoData);3570 bix[0].Client(cShowNego, 1 shl 16 + 3, ShowNegoData); 3565 3571 end; 3566 3572 LastOffer := TOffer(Data); -
trunk/Start.pas
r144 r145 963 963 begin 964 964 WriteString('DefaultAI', BrainDefault.FileName); 965 SlotAvailable := 0; // bixViewwill be invalid hereafter965 SlotAvailable := 0; // PlayerSlot will be invalid hereafter 966 966 PlayersBrain[0] := BrainTerm; 967 967 Difficulty[0] := PlayerAutoDiff[AutoDiff];
Note:
See TracChangeset
for help on using the changeset viewer.