author | unc0rr |
Wed, 16 Dec 2015 00:20:56 +0300 | |
branch | qmlfrontend |
changeset 11458 | 8318e841648f |
parent 11456 | ab77e2ea2f82 |
permissions | -rw-r--r-- |
10434
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
1 |
unit uFLTeams; |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
2 |
interface |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
3 |
uses uFLTypes; |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
4 |
|
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
5 |
function createRandomTeam: TTeam; |
11458 | 6 |
procedure sendTeamConfig(hp: LongInt; var team: TTeam); |
10434
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
7 |
|
10440 | 8 |
function getTeamsList: PPChar; cdecl; |
9 |
procedure freeTeamsList; |
|
10434
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
10 |
|
10446 | 11 |
function teamByName(s: shortstring): PTeam; |
12 |
||
11444 | 13 |
procedure sendTeam(var team: TTeam); |
11446 | 14 |
procedure removeTeam(teamName: shortstring); |
11444 | 15 |
|
10434
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
16 |
implementation |
11456 | 17 |
uses uFLUtils, uFLIPC, uPhysFSLayer, uFLThemes, uFLNet; |
10440 | 18 |
|
19 |
const MAX_TEAM_NAMES = 128; |
|
20 |
var |
|
21 |
teamsList: PTeam; |
|
22 |
teamsNumber: Longword; |
|
23 |
listOfTeamNames: array[0..MAX_TEAM_NAMES] of PChar; |
|
24 |
||
10434
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
25 |
|
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
26 |
function createRandomTeam: TTeam; |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
27 |
var t: TTeam; |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
28 |
i: Longword; |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
29 |
begin |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
30 |
with t do |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
31 |
begin |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
32 |
teamName:= 'team' + inttostr(random(100)); |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
33 |
|
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
34 |
for i:= 0 to 7 do |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
35 |
with hedgehogs[i] do |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
36 |
begin |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
37 |
name:= 'hedgehog ' + inttostr(i); |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
38 |
hat:= 'NoHat' |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
39 |
end; |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
40 |
|
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
41 |
botLevel:= 0; |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
42 |
hogsNumber:= 4 |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
43 |
end; |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
44 |
createRandomTeam:= t |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
45 |
end; |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
46 |
|
10440 | 47 |
|
11458 | 48 |
procedure sendTeamConfig(hp: LongInt; var team: TTeam); |
10434
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
49 |
var i: Longword; |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
50 |
begin |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
51 |
with team do |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
52 |
begin |
10450 | 53 |
ipcToEngine('eaddteam <hash> ' + colorsSet[color] + ' ' + teamName); |
11455 | 54 |
|
11454 | 55 |
if extDriven then |
11455 | 56 |
ipcToEngine('erdriven'); |
57 |
||
10434
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
58 |
for i:= 0 to Pred(hogsNumber) do |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
59 |
begin |
11458 | 60 |
ipcToEngine('eaddhh ' + IntToStr(botLevel) + ' ' + IntToStr(hp) + ' ' + hedgehogs[i].name); |
11454 | 61 |
ipcToEngine('ehat ' + hedgehogs[i].hat); |
10434
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
62 |
end; |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
63 |
end |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
64 |
end; |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
65 |
|
10440 | 66 |
|
67 |
procedure loadTeam(var team: TTeam; fileName: shortstring); |
|
68 |
var f: PFSFile; |
|
69 |
section: LongInt; |
|
70 |
l: shortstring; |
|
71 |
begin |
|
72 |
section:= -1; |
|
73 |
f:= pfsOpenRead(fileName); |
|
74 |
||
75 |
while (not pfsEOF(f)) do |
|
76 |
begin |
|
77 |
pfsReadLn(f, l); |
|
78 |
||
79 |
if l = '' then |
|
80 |
else if l = '[Team]' then |
|
11445 | 81 |
section:= -2 |
82 |
else if copy(l, 1, 9) = '[Hedgehog' then |
|
83 |
section:= StrToInt(copy(l, 10, 1)) |
|
84 |
else if section = -2 then |
|
10440 | 85 |
begin // [Team] |
86 |
if copy(l, 1, 5) = 'Name=' then |
|
87 |
team.teamName:= midStr(l, 6) |
|
88 |
else if copy(l, 1, 6) = 'Grave=' then |
|
11442 | 89 |
team.grave:= midStr(l, 7) |
10440 | 90 |
else if copy(l, 1, 5) = 'Fort=' then |
11442 | 91 |
team.fort:= midStr(l, 6) |
10440 | 92 |
else if copy(l, 1, 5) = 'Flag=' then |
93 |
team.flag:= midStr(l, 6) |
|
11445 | 94 |
else if copy(l, 1, 10) = 'Voicepack=' then |
95 |
team.voice:= midStr(l, 11) |
|
96 |
else if copy(l, 1, 11) = 'Difficulty=' then |
|
97 |
team.botLevel:= StrToInt(midStr(l, 12)) |
|
98 |
end else if (section >= 0) and (section <= 7) then |
|
99 |
begin // [Hedgehog*] |
|
100 |
if copy(l, 1, 5) = 'Name=' then |
|
101 |
team.hedgehogs[section].name:= midStr(l, 6) |
|
102 |
else if copy(l, 1, 4) = 'Hat=' then |
|
103 |
team.hedgehogs[section].hat:= midStr(l, 5) |
|
10440 | 104 |
end; |
105 |
end; |
|
106 |
||
107 |
pfsClose(f) |
|
108 |
end; |
|
109 |
||
110 |
||
111 |
procedure loadTeams; |
|
112 |
var filesList, tmp: PPChar; |
|
113 |
team: PTeam; |
|
114 |
s: shortstring; |
|
115 |
l: Longword; |
|
116 |
begin |
|
10442 | 117 |
filesList:= pfsEnumerateFiles('/Config/Teams'); |
10440 | 118 |
teamsNumber:= 0; |
119 |
||
120 |
tmp:= filesList; |
|
121 |
while tmp^ <> nil do |
|
122 |
begin |
|
123 |
s:= shortstring(tmp^); |
|
124 |
l:= length(s); |
|
10442 | 125 |
if (l > 4) and (copy(s, l - 3, 4) = '.hwt') then inc(teamsNumber); |
126 |
inc(tmp) |
|
10440 | 127 |
end; |
128 |
||
129 |
// TODO: no teams at all? |
|
130 |
teamsList:= GetMem(sizeof(teamsList^) * teamsNumber); |
|
131 |
||
132 |
team:= teamsList; |
|
133 |
tmp:= filesList; |
|
134 |
while tmp^ <> nil do |
|
135 |
begin |
|
136 |
s:= shortstring(tmp^); |
|
137 |
l:= length(s); |
|
138 |
if (l > 4) and (copy(s, l - 3, 4) = '.hwt') then |
|
139 |
begin |
|
140 |
loadTeam(team^, '/Config/Teams/' + s); |
|
141 |
inc(team) |
|
142 |
end; |
|
10442 | 143 |
inc(tmp) |
10440 | 144 |
end; |
145 |
||
146 |
pfsFreeList(filesList) |
|
147 |
end; |
|
148 |
||
149 |
||
150 |
function getTeamsList: PPChar; cdecl; |
|
151 |
var i, t, l: Longword; |
|
152 |
team: PTeam; |
|
153 |
begin |
|
154 |
if teamsList = nil then |
|
155 |
loadTeams; |
|
156 |
||
157 |
t:= teamsNumber; |
|
158 |
if t >= MAX_TEAM_NAMES then |
|
159 |
t:= MAX_TEAM_NAMES; |
|
160 |
||
161 |
team:= teamsList; |
|
162 |
for i:= 0 to Pred(t) do |
|
163 |
begin |
|
164 |
l:= length(team^.teamName); |
|
165 |
if l >= 255 then l:= 254; |
|
166 |
team^.teamName[l + 1]:= #0; |
|
10442 | 167 |
listOfTeamNames[i]:= @team^.teamName[1]; |
168 |
inc(team) |
|
10440 | 169 |
end; |
170 |
||
171 |
listOfTeamNames[t]:= nil; |
|
172 |
||
173 |
getTeamsList:= listOfTeamNames |
|
174 |
end; |
|
175 |
||
10446 | 176 |
function teamByName(s: shortstring): PTeam; |
177 |
var i: Longword; |
|
178 |
team: PTeam; |
|
179 |
begin |
|
180 |
team:= teamsList; |
|
181 |
i:= 0; |
|
182 |
while (i < teamsNumber) and (team^.teamName <> s) do |
|
183 |
begin |
|
184 |
inc(team); |
|
185 |
inc(i) |
|
186 |
end; |
|
187 |
||
188 |
if i < teamsNumber then teamByName:= team else teamByName:= nil |
|
189 |
end; |
|
10440 | 190 |
|
191 |
procedure freeTeamsList; |
|
192 |
begin |
|
193 |
if teamsList <> nil then |
|
194 |
FreeMem(teamsList, sizeof(teamsList^) * teamsNumber) |
|
195 |
end; |
|
196 |
||
11444 | 197 |
procedure sendTeam(var team: TTeam); |
198 |
var i: Longword; |
|
199 |
begin |
|
200 |
with team do |
|
201 |
begin |
|
202 |
sendNetLn('ADD_TEAM'); |
|
203 |
sendNetLn(teamName); |
|
204 |
sendNetLn(IntToStr(color)); |
|
205 |
sendNetLn(grave); |
|
206 |
sendNetLn(fort); |
|
207 |
sendNetLn(voice); |
|
208 |
sendNetLn(flag); |
|
209 |
sendNetLn(IntToStr(botLevel)); |
|
210 |
for i := 0 to 7 do |
|
211 |
begin |
|
212 |
sendNetLn(hedgehogs[i].name); |
|
213 |
sendNetLn(hedgehogs[i].hat); |
|
214 |
end; |
|
215 |
sendNetLn('') |
|
216 |
end; |
|
217 |
end; |
|
218 |
||
11446 | 219 |
procedure removeTeam(teamName: shortstring); |
220 |
begin |
|
221 |
sendNetLn('REMOVE_TEAM'); |
|
222 |
sendNet(teamName) |
|
223 |
end; |
|
224 |
||
10434
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
225 |
end. |