-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathBaseConflict.Game.Client.pas
178 lines (153 loc) · 4.91 KB
/
BaseConflict.Game.Client.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
unit BaseConflict.Game.Client;
interface
uses
System.UITypes,
generics.Collections,
generics.defaults,
Engine.Helferlein,
Engine.Helferlein.Windows,
Engine.Math,
BaseConflict.Constants,
BaseConflict.Constants.Scenario,
Engine.Terrain,
{$IFDEF DEBUG}
Engine.Terrain.Editor,
{$ENDIF}
Engine.Serializer,
Engine.Collision,
Engine.Core,
Engine.Script,
Engine.Network,
BaseConflict.Entity,
BaseConflict.Game,
BaseConflict.EntityComponents.Shared,
BaseConflict.EntityComponents.Client,
BaseConflict.Map,
BaseConflict.Map.Client,
BaseConflict.Types.Client,
SysUtils,
Vcl.Dialogs,
Math,
RTTI,
Vcl.Forms;
type
{$RTTI EXPLICIT METHODS([vcPublic]) FIELDS([vcProtected,vcPublic]) PROPERTIES([vcProtected, vcPublic])}
[ScriptExcludeAll]
TClientGame = class(TGame)
protected
FGameState : EnumGameStatus;
FTokenMapping : TList<integer>;
FClientMap : TClientMap;
FClientNetworkComponent : TClientNetworkComponent;
FClientInputComponent : TClientInputComponent;
procedure OnTokenMapping(TokenMapping : TList<integer>);
procedure FinishedReceiveGameData;
public
MinimapManager : TMiniMapComponent;
CommanderManager : TCommanderManagerComponent;
DecayManager : TUnitDecayManagerComponent;
TraceManager : TVertexTraceManagerComponent;
BuildgridManager : TBuildGridManagerComponent;
property GameState : EnumGameStatus read FGameState write FGameState;
function IsReady : boolean;
function IsRunning : boolean;
function IsFinished : boolean;
[ScriptIncludeMember]
property ClientMap : TClientMap read FClientMap;
constructor Create(GameInfo : TGameInformation; Socket : TTCPClientSocketDeluxe; const AuthentificationToken : string; TokenMapping : TList<integer>);
function Ping : integer;
procedure Initialize; override;
procedure Idle; override;
destructor Destroy; override;
end;
implementation
uses
BaseConflict.Globals,
BaseConflict.Globals.Client,
BaseConflict.EntityComponents.Client.GUI,
BaseConflict.EntityComponents.Client.Sound;
{ TClientGame }
constructor TClientGame.Create(GameInfo : TGameInformation; Socket : TTCPClientSocketDeluxe; const AuthentificationToken : string; TokenMapping : TList<integer>);
var
Map : string;
begin
inherited Create(GameInfo);
FGameState := gsPreparing;
FTokenMapping := TokenMapping;
if FGameInfo.Scenario.MapName <> '' then
begin
Map := FormatDateiPfad(PATH_MAP + FGameInfo.Scenario.MapName + '\' + FGameInfo.Scenario.MapName + '.bcm');
FClientMap := TClientMap.CreateFromFile(Map);
BaseConflict.Globals.Client.ClientMap := FClientMap;
end
else raise EFileNotFoundException.Create('TClientGame.Create: Mapname should not be empty!');
CollisionManager := TCollisionManagerComponent.Create(GameEntity);
FEntityManager := TClientEntityManagerComponent.Create(GameEntity);
FClientNetworkComponent := TClientNetworkComponent.Create(GameEntity, Socket, AuthentificationToken, FinishedReceiveGameData);
FClientInputComponent := TClientInputComponent.Create(GameEntity);
TClientCameraComponent.Create(GameEntity);
TClientGUIComponent.Create(GameEntity);
TGameSoundManagerComponent.Create(GameEntity);
CommanderManager := TCommanderManagerComponent.Create(GameEntity);
DecayManager := TUnitDecayManagerComponent.Create(GameEntity);
TraceManager := TVertexTraceManagerComponent.Create(GameEntity);
MinimapManager := TMiniMapComponent.Create(GameEntity);
if FGameInfo.Scenario.MapName = 'Single' then
MinimapManager.Minimap.IsSingleMap;
Initialize;
// build zones are set by scripts in initialize
BuildgridManager := TBuildGridManagerComponent.Create(GameEntity);
end;
destructor TClientGame.Destroy;
begin
FTokenMapping.Free;
FClientMap.Free;
FClientInputComponent.ClearAction;
BaseConflict.Globals.Client.ClientMap := nil;
inherited;
end;
procedure TClientGame.FinishedReceiveGameData;
begin
OnTokenMapping(FTokenMapping);
end;
procedure TClientGame.Idle;
begin
ClientMap.Idle;
inherited;
end;
procedure TClientGame.Initialize;
begin
inherited;
end;
function TClientGame.IsFinished : boolean;
begin
Result := GameState in [gsAborted, gsCrashed, gsFinished];
end;
function TClientGame.IsReady : boolean;
begin
Result := not(GameState in [gsPreparing]);
end;
function TClientGame.IsRunning : boolean;
begin
Result := GameState in [gsPreparing, gsRunning, gsReconnecting];
end;
procedure TClientGame.OnTokenMapping(TokenMapping : TList<integer>);
var
i : integer;
Entity : TEntity;
begin
CommanderManager.ClearCommanders;
for i := 0 to TokenMapping.Count - 1 do
begin
Entity := EntityManager.GetEntityByID(TokenMapping[i]);
GlobalEventbus.Trigger(eiNewCommander, [Entity]);
end;
GameState := gsRunning;
end;
function TClientGame.Ping : integer;
begin
Result := FClientNetworkComponent.Ping;
end;
initialization
ScriptManager.ExposeClass(TClientGame);
end.