Changeset 378 for branches/highdpi/GameServer.pas
- Timestamp:
- Apr 24, 2021, 11:41:07 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/highdpi/GameServer.pas
r361 r378 7 7 8 8 uses 9 UDpiControls,Protocol, Database, dynlibs, Platform, dateutils, fgl, LazFileUtils,10 Graphics ;9 Protocol, Database, dynlibs, Platform, dateutils, fgl, LazFileUtils, 10 Graphics, UBrain; 11 11 12 12 const … … 14 14 FirstAICompatibleVersion = $000D00; 15 15 FirstBookCompatibleVersion = $010103; 16 17 // module flags18 fMultiple = $10000000;19 fDotNet = $20000000;20 fUsed = $40000000;21 16 22 17 maxBrain = 255; … … 52 47 TNotifyFunction = procedure(ID: TNotify; Index: Integer = 0); 53 48 54 TBrainType = (btNoTerm, btSuperVirtual, btTerm, btRandom, btAI);55 56 { TBrain }57 58 TBrain = class59 FileName: string;60 DLLName: string;61 Name: string;62 Credits: string; { filename and full name }63 hm: TLibHandle; { module handle }64 Flags: Integer;65 ServerVersion: Integer;66 DataVersion: Integer;67 DataSize: Integer;68 Client: TClientCall; { client function address }69 Initialized: Boolean;70 Kind: TBrainType;71 Picture: TDpiBitmap;72 procedure LoadFromFile(AIFileName: string);73 constructor Create;74 destructor Destroy; override;75 end;76 77 { TBrains }78 79 TBrains = class(TFPGObjectList<TBrain>)80 function AddNew: TBrain;81 function GetKindCount(Kind: TBrainType): Integer;82 procedure GetByKind(Kind: TBrainType; Brains: TBrains);83 end;84 85 49 var 86 50 // PARAMETERS 87 PlayersBrain: TBrains; { brain of the players }51 PlayersBrain: TBrains; { brain of the players view } 88 52 Difficulty: array [0 .. nPl - 1] of integer absolute Database.Difficulty; 89 53 { difficulty } … … 98 62 BrainTerm: TBrain; 99 63 BrainRandom: TBrain; 100 BrainBeginner: TBrain; // AI to use for beginner level 64 BrainNetworkClient: TBrain; 65 BrainNetworkServer: TBrain; 66 67 NetworkEnabled: Boolean; 101 68 102 69 procedure Init(NotifyFunction: TNotifyFunction); … … 184 151 {$ELSE} 185 152 try 186 Brain[bix[p]].Client(Command, p, Data);153 bix[p].Client(Command, p, Data); 187 154 except 188 155 Notify(ntException + bix[p]); … … 190 157 {$ENDIF} 191 158 end 159 end; 160 161 procedure CallAllPlayers(Command: Integer; var Data); 162 var 163 I: Integer; 164 begin 165 for I := 0 to nPl - 1 do 166 if Assigned(bix[I]) then 167 CallPlayer(Command, I, Data); 192 168 end; 193 169 … … 236 212 BrainNoTerm.FileName := ':AIT'; 237 213 BrainNoTerm.Flags := 0; 238 BrainNoTerm.Initialized := false;214 BrainNoTerm.Initialized := False; 239 215 BrainNoTerm.Kind := btNoTerm; 240 216 BrainSuperVirtual := Brains.AddNew; 241 217 BrainSuperVirtual.FileName := ':Supervisor'; 242 218 BrainSuperVirtual.Flags := 0; 243 BrainSuperVirtual.Initialized := false;219 BrainSuperVirtual.Initialized := False; 244 220 BrainSuperVirtual.Kind := btSuperVirtual; 221 if NetworkEnabled then begin 222 BrainNetworkClient := Brains.AddNew; 223 BrainNetworkClient.FileName := ':NetworkClient'; 224 BrainNetworkClient.Flags := fMultiple; 225 BrainNetworkClient.Initialized := False; 226 BrainNetworkClient.ServerVersion := Version; 227 BrainNetworkClient.Kind := btNetworkClient; 228 end; 245 229 BrainTerm := Brains.AddNew; 246 230 BrainTerm.FileName := ':StdIntf'; 247 231 BrainTerm.Flags := fMultiple; 248 BrainTerm.Initialized := false;232 BrainTerm.Initialized := False; 249 233 BrainTerm.ServerVersion := Version; 250 234 BrainTerm.Kind := btTerm; … … 252 236 BrainRandom.FileName := ':Random'; 253 237 BrainRandom.Flags := fMultiple; 254 BrainRandom.Initialized := false;238 BrainRandom.Initialized := False; 255 239 BrainRandom.Kind := btRandom; 256 257 BrainBeginner := nil; 240 if NetworkEnabled then begin 241 BrainNetworkServer := Brains.AddNew; 242 BrainNetworkServer.FileName := ':NetworkServer'; 243 BrainNetworkServer.Flags := fMultiple; 244 BrainNetworkServer.Initialized := False; 245 BrainNetworkServer.ServerVersion := Version; 246 BrainNetworkServer.Kind := btNetworkServer; 247 end; 258 248 259 249 if FindFirst(GetAiDir + DirectorySeparator + '*', faDirectory or faArchive or faReadOnly, f) = 0 then … … 369 359 Notify(ntDeactivationMissing, p); 370 360 ForceClientDeactivation; 371 end 361 end; 372 362 end; 373 363 … … 1355 1345 begin 1356 1346 CL.State := FormerCLState; 1357 Break 1358 end 1347 Break; 1348 end; 1359 1349 end; 1360 1350 {$IFOPT O-}InvalidTreatyMap := 0; {$ENDIF} … … 1364 1354 Newlx, Newly, NewLandMass, NewMaxTurn: integer); 1365 1355 var 1366 p: integer;1356 I: Integer; 1367 1357 begin 1368 1358 Notify(ntStartDone); … … 1389 1379 StartGame; 1390 1380 NoLogChanges; 1391 for p := 0 to nPl - 1 do 1392 if Assigned(bix[p]) then 1393 CallPlayer(cGetReady, p, nil^); 1381 CallAllPlayers(cGetReady, nil^); 1394 1382 LogChanges; 1395 1383 CL.Put(sTurn, 0, 0, nil); … … 1399 1387 nLogOpened := -1; 1400 1388 LastEndClientCommand := -1; 1401 bix[0].Client(cShowGame, 0, nil^); 1389 CallPlayer(cShowGame, 0, nil^); 1390 for I := 0 to nPl - 1 do 1391 if Assigned(bix[I]) and (bix[I].Kind = btNetworkServer) then 1392 CallPlayer(cShowGame, I, nil^); 1402 1393 Notify(ntBackOff); 1403 1394 Inform(pTurn); … … 1505 1496 CallPlayer(cShowShipChange, p1, ShowShipChange); 1506 1497 end; 1507 end 1508 end 1498 end; 1499 end; 1509 1500 end; 1510 1501 … … 2425 2416 if PModel.Attack = 0 then 2426 2417 Flags := Flags and not unBombsLoaded; 2427 dec(Movement, 100) 2418 dec(Movement, 100); 2428 2419 end 2429 2420 else if MoveInfo.MoveType = mtExpel then … … 2432 2423 Job := jNone; 2433 2424 Flags := Flags and not unFortified; 2434 dec(Movement, 100) 2425 dec(Movement, 100); 2435 2426 end 2436 2427 else … … 2482 2473 inc(nUpdateLoc); 2483 2474 Flags := Flags or unWithdrawn; 2484 end 2475 end; 2485 2476 end 2486 2477 else if (MoveInfo.MoveType = mtAttack) and (MoveInfo.EndHealthDef > 0) then … … 2520 2511 begin 2521 2512 UpdateLoc[nUpdateLoc] := Loc; 2522 inc(nUpdateLoc) 2513 inc(nUpdateLoc); 2523 2514 end; 2524 2515 // unit will be removed -- remember position and update for all players … … 2568 2559 CallPlayer(cShowUnitChanged, p1, ExpelToLoc); 2569 2560 end; 2570 end 2571 end 2561 end; 2562 end; 2572 2563 end; // ExecuteAttack 2573 2564 … … 2585 2576 begin 2586 2577 result := eInvalid; 2587 exit 2578 exit; 2588 2579 end; 2589 2580 result := CalculateMove(p, uix, ToLoc, 3 - dy and 1, TestOnly, MoveInfo); … … 2619 2610 result := ExecuteMove(p, uix, ToLoc, MoveInfo, ShowMove) or result; 2620 2611 mtAttack, mtBombard, mtExpel: 2621 result := ExecuteAttack(p, uix, ToLoc, MoveInfo, ShowMove) or result 2622 end; 2623 end 2612 result := ExecuteAttack(p, uix, ToLoc, MoveInfo, ShowMove) or result; 2613 end; 2614 end; 2624 2615 end; // with 2625 2616 end; { MoveUnit } … … 2695 2686 result := ptShip 2696 2687 else 2697 result := ptImp 2688 result := ptImp; 2698 2689 end; 2699 2690 … … 2726 2717 begin 2727 2718 result := eUnknown; 2728 exit 2719 exit; 2729 2720 end; 2730 2721 … … 2734 2725 begin 2735 2726 result := eInvalid; 2736 exit 2727 exit; 2737 2728 end; 2738 2729 … … 2744 2735 PutMessage(1 shl 16 + 1, Format('NOT Alive: %d', [Player])); 2745 2736 result := eNoTurn; 2746 exit 2737 exit; 2747 2738 end; 2748 2739 … … 2771 2762 [Player, Command shr 4])); 2772 2763 result := eNoTurn; 2773 exit 2764 exit; 2774 2765 end; 2775 2766 … … 2897 2888 else 2898 2889 result := GetTileInfo(Player, TTileInfo(Data).ExplCity, Subject, 2899 TTileInfo(Data)) 2890 TTileInfo(Data)); 2900 2891 end 2901 2892 else … … 2908 2899 result := eNoPreq 2909 2900 else 2910 result := GetJobProgress(Player, Subject, TJobProgressData(Data)) 2901 result := GetJobProgress(Player, Subject, TJobProgressData(Data)); 2911 2902 end 2912 2903 else … … 2957 2948 end; 2958 2949 if result = eOK then 2959 result := eInvalid // no enemy unit there!2950 result := eInvalid; // no enemy unit there! 2960 2951 end 2961 2952 else … … 2988 2979 result := eOK 2989 2980 else 2990 result := eNoWay 2981 result := eNoWay; 2991 2982 end; 2992 2983 … … 3040 3031 TCityReport(Data).HypoTax := -1; 3041 3032 TCityReport(Data).HypoLux := -1; 3042 GetCityReport(p1, cix1, TCityReport(Data)) 3033 GetCityReport(p1, cix1, TCityReport(Data)); 3043 3034 end 3044 3035 else … … 3071 3062 p1 := 1; 3072 3063 SearchCity(Subject, p1, cix1); 3073 GetCityAreaInfo(p1, Subject, TCityAreaInfo(Data)) 3064 GetCityAreaInfo(p1, Subject, TCityAreaInfo(Data)); 3074 3065 end 3075 3066 else … … 3135 3126 LogChanges; 3136 3127 SaveGame('~' + LogFileName, true); 3137 end 3128 end; 3138 3129 {$ENDIF} 3139 3130 end … … 3164 3155 begin 3165 3156 if CheckSum <> Subject then 3166 LoadOK := false 3157 LoadOK := false; 3167 3158 end 3168 3159 else // save checksum … … 3210 3201 CCCommand := cTurn; 3211 3202 CCPlayer := pTurn; 3212 Notify(ntNextPlayer) 3203 Notify(ntNextPlayer); 3213 3204 end 3214 3205 else … … 3274 3265 sReload: 3275 3266 LoadGame(SavePath, LogFileName, integer(Data), false); 3276 end 3267 end; 3277 3268 end 3278 3269 else … … 3291 3282 Notify(ntStartGoRefreshMaps) 3292 3283 else 3293 Notify(ntStartGo) 3284 Notify(ntStartGo); 3294 3285 end 3295 3286 else … … 3331 3322 assert(Mode = moPlaying); 3332 3323 ChangeClientWhenDone(cContinue, pTurn, nil^, 0); 3333 end 3324 end; 3334 3325 end 3335 3326 else … … 3348 3339 IntServer(sIntHaveContact, pTurn, pContacted, nil^); 3349 3340 ChangeClientWhenDone(scDipStart, pDipActive, nil^, 0); 3350 end 3341 end; 3351 3342 end 3352 3343 else … … 3407 3398 ShowShipChange.Ship2Change[Price[i] shr 16 and 3] := 3408 3399 +integer(Price[i] and $FFFF); 3409 end 3400 end; 3410 3401 end; 3411 3402 if HasShipChanged then … … 3421 3412 if 1 shl p2 and GWatching <> 0 then 3422 3413 CallPlayer(cShowShipChange, p2, ShowShipChange); 3423 end 3424 end 3414 end; 3415 end; 3425 3416 end; 3426 3417 end … … 3447 3438 CallPlayer(cShowCancelTreatyByAlliance, pDipActive, i); 3448 3439 end; 3449 end 3440 end; 3450 3441 end 3451 3442 else … … 3470 3461 pDipActive := p1; 3471 3462 ChangeClientWhenDone(Command, pDipActive, nil^, 0); 3472 end 3463 end; 3473 3464 end 3474 3465 else … … 3488 3479 assert(Mode = moPlaying); 3489 3480 ChangeClientWhenDone(cContinue, pTurn, nil^, 0); 3490 end 3481 end; 3491 3482 end 3492 3483 else … … 4504 4495 end; { <<<server } 4505 4496 4506 function ExtractFileNameWithoutExt(const Filename: string): string;4507 var4508 P: Integer;4509 begin4510 Result := Filename;4511 P := Length(Result);4512 while P > 0 do begin4513 case Result[P] of4514 PathDelim: Exit;4515 {$ifdef windows}4516 '/': if ('/' in AllowDirectorySeparators) then Exit;4517 {$endif}4518 '.': Exit(Copy(Result, 1, P - 1));4519 end;4520 Dec(P);4521 end;4522 end;4523 4524 { TBrain }4525 4526 procedure TBrain.LoadFromFile(AIFileName: string);4527 var4528 T: Text;4529 Key: string;4530 Value: string;4531 S: string;4532 BasePath: string;4533 I: Integer;4534 begin4535 BasePath := ExtractFileDir(AIFileName);4536 FileName := ExtractFileName(ExtractFileNameWithoutExt(ExtractFileNameWithoutExt(AIFileName)));4537 Name := FileName;4538 DLLName := BasePath + DirectorySeparator + Name + '.dll';4539 Credits := '';4540 Flags := fMultiple;4541 Client := nil;4542 Initialized := false;4543 ServerVersion := 0;4544 if not FileExists(AIFileName) then4545 raise Exception.Create(Format('AI specification file %s not found', [AIFileName]));4546 AssignFile(T, AIFileName);4547 Reset(T);4548 while not EOF(T) do4549 begin4550 ReadLn(T, s);4551 s := trim(s);4552 if Pos(' ', S) > 0 then begin4553 Key := Copy(S, 1, Pos(' ', S) - 1);4554 Value := Trim(Copy(S, Pos(' ', S) + 1, Length(S)));4555 end else begin4556 Key := S;4557 Value := '';4558 end;4559 if Key = '#NAME' then4560 Name := Value4561 else if Key = '#.NET' then4562 Flags := Flags or fDotNet4563 else if Key = '#BEGINNER' then4564 BrainBeginner := Self4565 else if Key = '#PATH' then4566 DLLName := BasePath + DirectorySeparator + Value4567 {$IFDEF WINDOWS}{$IFDEF CPU32}4568 else if Key = '#PATH_WIN32' then4569 DLLName := BasePath + DirectorySeparator + Value4570 {$ENDIF}{$ENDIF}4571 {$IFDEF WINDOWS}{$IFDEF CPU64}4572 else if Key = '#PATH_WIN64' then4573 DLLName := BasePath + DirectorySeparator + Value4574 {$ENDIF}{$ENDIF}4575 {$IFDEF LINUX}{$IFDEF CPU32}4576 else if Key = '#PATH_LINUX32' then4577 DLLName := BasePath + DirectorySeparator + Value4578 {$ENDIF}{$ENDIF}4579 {$IFDEF LINUX}{$IFDEF CPU64}4580 else if Key = '#PATH_LINUX64' then4581 DLLName := BasePath + DirectorySeparator + Value4582 {$ENDIF}{$ENDIF}4583 else if Key = '#GAMEVERSION' then4584 for i := 1 to Length(Value) do4585 case Value[i] of4586 '0' .. '9':4587 ServerVersion := ServerVersion and $FFFF00 + ServerVersion and4588 $FF * 10 + ord(Value[i]) - 48;4589 '.':4590 ServerVersion := ServerVersion shl 8;4591 end4592 else if Key = '#CREDITS' then4593 Credits := Value;4594 end;4595 CloseFile(T);4596 end;4597 4598 constructor TBrain.Create;4599 begin4600 Picture := TDpiBitmap.Create;4601 Picture.SetSize(64, 64);4602 end;4603 4604 destructor TBrain.Destroy;4605 begin4606 FreeAndNil(Picture);4607 inherited;4608 end;4609 4610 { TBrains }4611 4612 function TBrains.AddNew: TBrain;4613 begin4614 Result := TBrain.Create;4615 Add(Result);4616 end;4617 4618 function TBrains.GetKindCount(Kind: TBrainType): Integer;4619 var4620 I: Integer;4621 begin4622 Result := 0;4623 for I := 0 to Count - 1 do4624 if Items[I].Kind = Kind then Inc(Result);4625 end;4626 4627 procedure TBrains.GetByKind(Kind: TBrainType; Brains: TBrains);4628 var4629 I: Integer;4630 begin4631 Brains.Clear;4632 for I := 0 to Count - 1 do4633 if Items[I].Kind = Kind then Brains.Add(Items[I]);4634 end;4635 4497 4636 4498 initialization
Note:
See TracChangeset
for help on using the changeset viewer.