author | unc0rr |
Sun, 06 Dec 2015 19:56:33 +0300 | |
branch | qmlfrontend |
changeset 11444 | 91f8c6ff5bab |
parent 11442 | 6b04a266feee |
child 11445 | 465b4db35232 |
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 |
|
76 |
section:= 0 |
|
77 |
else if l[1] = '[' then |
|
78 |
section:= -1 |
|
79 |
else if section = 0 then |
|
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) |
|
89 |
end; |
|
90 |
// TODO: load hedgehogs and other stuff |
|
11437 | 91 |
team.botLevel:= 0 |
10440 | 92 |
end; |
93 |
||
94 |
pfsClose(f) |
|
95 |
end; |
|
96 |
||
97 |
||
98 |
procedure loadTeams; |
|
99 |
var filesList, tmp: PPChar; |
|
100 |
team: PTeam; |
|
101 |
s: shortstring; |
|
102 |
l: Longword; |
|
103 |
begin |
|
10442 | 104 |
filesList:= pfsEnumerateFiles('/Config/Teams'); |
10440 | 105 |
teamsNumber:= 0; |
106 |
||
107 |
tmp:= filesList; |
|
108 |
while tmp^ <> nil do |
|
109 |
begin |
|
110 |
s:= shortstring(tmp^); |
|
111 |
l:= length(s); |
|
10442 | 112 |
if (l > 4) and (copy(s, l - 3, 4) = '.hwt') then inc(teamsNumber); |
113 |
inc(tmp) |
|
10440 | 114 |
end; |
115 |
||
116 |
// TODO: no teams at all? |
|
117 |
teamsList:= GetMem(sizeof(teamsList^) * teamsNumber); |
|
118 |
||
119 |
team:= teamsList; |
|
120 |
tmp:= filesList; |
|
121 |
while tmp^ <> nil do |
|
122 |
begin |
|
123 |
s:= shortstring(tmp^); |
|
124 |
l:= length(s); |
|
125 |
if (l > 4) and (copy(s, l - 3, 4) = '.hwt') then |
|
126 |
begin |
|
127 |
loadTeam(team^, '/Config/Teams/' + s); |
|
128 |
inc(team) |
|
129 |
end; |
|
10442 | 130 |
inc(tmp) |
10440 | 131 |
end; |
132 |
||
133 |
pfsFreeList(filesList) |
|
134 |
end; |
|
135 |
||
136 |
||
137 |
function getTeamsList: PPChar; cdecl; |
|
138 |
var i, t, l: Longword; |
|
139 |
team: PTeam; |
|
140 |
begin |
|
141 |
if teamsList = nil then |
|
142 |
loadTeams; |
|
143 |
||
144 |
t:= teamsNumber; |
|
145 |
if t >= MAX_TEAM_NAMES then |
|
146 |
t:= MAX_TEAM_NAMES; |
|
147 |
||
148 |
team:= teamsList; |
|
149 |
for i:= 0 to Pred(t) do |
|
150 |
begin |
|
151 |
l:= length(team^.teamName); |
|
152 |
if l >= 255 then l:= 254; |
|
153 |
team^.teamName[l + 1]:= #0; |
|
10442 | 154 |
listOfTeamNames[i]:= @team^.teamName[1]; |
155 |
inc(team) |
|
10440 | 156 |
end; |
157 |
||
158 |
listOfTeamNames[t]:= nil; |
|
159 |
||
160 |
getTeamsList:= listOfTeamNames |
|
161 |
end; |
|
162 |
||
10446 | 163 |
function teamByName(s: shortstring): PTeam; |
164 |
var i: Longword; |
|
165 |
team: PTeam; |
|
166 |
begin |
|
167 |
team:= teamsList; |
|
168 |
i:= 0; |
|
169 |
while (i < teamsNumber) and (team^.teamName <> s) do |
|
170 |
begin |
|
171 |
inc(team); |
|
172 |
inc(i) |
|
173 |
end; |
|
174 |
||
175 |
if i < teamsNumber then teamByName:= team else teamByName:= nil |
|
176 |
end; |
|
10440 | 177 |
|
178 |
procedure freeTeamsList; |
|
179 |
begin |
|
180 |
if teamsList <> nil then |
|
181 |
FreeMem(teamsList, sizeof(teamsList^) * teamsNumber) |
|
182 |
end; |
|
183 |
||
11444 | 184 |
procedure sendTeam(var team: TTeam); |
185 |
var i: Longword; |
|
186 |
begin |
|
187 |
with team do |
|
188 |
begin |
|
189 |
sendNetLn('ADD_TEAM'); |
|
190 |
sendNetLn(teamName); |
|
191 |
sendNetLn(IntToStr(color)); |
|
192 |
sendNetLn(grave); |
|
193 |
sendNetLn(fort); |
|
194 |
sendNetLn(voice); |
|
195 |
sendNetLn(flag); |
|
196 |
sendNetLn(IntToStr(botLevel)); |
|
197 |
for i := 0 to 7 do |
|
198 |
begin |
|
199 |
sendNetLn(hedgehogs[i].name); |
|
200 |
sendNetLn(hedgehogs[i].hat); |
|
201 |
end; |
|
202 |
sendNetLn('') |
|
203 |
end; |
|
204 |
end; |
|
205 |
||
10434
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
206 |
end. |