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