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