author | unc0rr |
Sat, 01 Nov 2014 22:51:07 +0300 | |
branch | qmlfrontend |
changeset 10450 | bf9e30b4ef9b |
parent 10448 | 4cb727e029fa |
child 10517 | 844bd43db47a |
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 |
||
10434
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
13 |
implementation |
10450 | 14 |
uses uFLUtils, uFLIPC, uPhysFSLayer, uFLData; |
10440 | 15 |
|
16 |
const MAX_TEAM_NAMES = 128; |
|
17 |
var |
|
18 |
teamsList: PTeam; |
|
19 |
teamsNumber: Longword; |
|
20 |
listOfTeamNames: array[0..MAX_TEAM_NAMES] of PChar; |
|
21 |
||
10434
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
22 |
|
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
23 |
function createRandomTeam: TTeam; |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
24 |
var t: TTeam; |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
25 |
i: Longword; |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
26 |
begin |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
27 |
with t do |
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 |
teamName:= 'team' + inttostr(random(100)); |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
30 |
|
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
31 |
for i:= 0 to 7 do |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
32 |
with hedgehogs[i] do |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
33 |
begin |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
34 |
name:= 'hedgehog ' + inttostr(i); |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
35 |
hat:= 'NoHat' |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
36 |
end; |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
37 |
|
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
38 |
botLevel:= 0; |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
39 |
hogsNumber:= 4 |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
40 |
end; |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
41 |
createRandomTeam:= t |
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 |
|
10440 | 44 |
|
10434
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
45 |
procedure sendTeamConfig(var team: TTeam); |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
46 |
var i: Longword; |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
47 |
begin |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
48 |
with team do |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
49 |
begin |
10450 | 50 |
ipcToEngine('eaddteam <hash> ' + colorsSet[color] + ' ' + teamName); |
10434
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
51 |
for i:= 0 to Pred(hogsNumber) do |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
52 |
begin |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
53 |
ipcToEngine('eaddhh ' + inttostr(botLevel) + ' 100 ' + hedgehogs[i].name); |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
54 |
ipcToEngine('ehat ' + hedgehogs[i].hat); |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
55 |
end; |
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
56 |
end |
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 |
|
10440 | 59 |
|
60 |
procedure loadTeam(var team: TTeam; fileName: shortstring); |
|
61 |
var f: PFSFile; |
|
62 |
section: LongInt; |
|
63 |
l: shortstring; |
|
64 |
begin |
|
65 |
section:= -1; |
|
66 |
f:= pfsOpenRead(fileName); |
|
67 |
||
68 |
while (not pfsEOF(f)) do |
|
69 |
begin |
|
70 |
pfsReadLn(f, l); |
|
71 |
||
72 |
if l = '' then |
|
73 |
else if l = '[Team]' then |
|
74 |
section:= 0 |
|
75 |
else if l[1] = '[' then |
|
76 |
section:= -1 |
|
77 |
else if section = 0 then |
|
78 |
begin // [Team] |
|
79 |
if copy(l, 1, 5) = 'Name=' then |
|
80 |
team.teamName:= midStr(l, 6) |
|
81 |
else if copy(l, 1, 6) = 'Grave=' then |
|
82 |
team.graveName:= midStr(l, 7) |
|
83 |
else if copy(l, 1, 5) = 'Fort=' then |
|
84 |
team.fortName:= midStr(l, 6) |
|
85 |
else if copy(l, 1, 5) = 'Flag=' then |
|
86 |
team.flag:= midStr(l, 6) |
|
87 |
end; |
|
88 |
// TODO: load hedgehogs and other stuff |
|
10448 | 89 |
team.botLevel:= 1 |
10440 | 90 |
end; |
91 |
||
92 |
pfsClose(f) |
|
93 |
end; |
|
94 |
||
95 |
||
96 |
procedure loadTeams; |
|
97 |
var filesList, tmp: PPChar; |
|
98 |
team: PTeam; |
|
99 |
s: shortstring; |
|
100 |
l: Longword; |
|
101 |
begin |
|
10442 | 102 |
filesList:= pfsEnumerateFiles('/Config/Teams'); |
10440 | 103 |
teamsNumber:= 0; |
104 |
||
105 |
tmp:= filesList; |
|
106 |
while tmp^ <> nil do |
|
107 |
begin |
|
108 |
s:= shortstring(tmp^); |
|
10442 | 109 |
writeln(stderr, '> ', s); |
10440 | 110 |
l:= length(s); |
10442 | 111 |
if (l > 4) and (copy(s, l - 3, 4) = '.hwt') then inc(teamsNumber); |
112 |
inc(tmp) |
|
10440 | 113 |
end; |
114 |
||
115 |
// TODO: no teams at all? |
|
116 |
teamsList:= GetMem(sizeof(teamsList^) * teamsNumber); |
|
117 |
||
118 |
team:= teamsList; |
|
119 |
tmp:= filesList; |
|
120 |
while tmp^ <> nil do |
|
121 |
begin |
|
122 |
s:= shortstring(tmp^); |
|
123 |
l:= length(s); |
|
124 |
if (l > 4) and (copy(s, l - 3, 4) = '.hwt') then |
|
125 |
begin |
|
126 |
loadTeam(team^, '/Config/Teams/' + s); |
|
127 |
inc(team) |
|
128 |
end; |
|
10442 | 129 |
inc(tmp) |
10440 | 130 |
end; |
131 |
||
132 |
pfsFreeList(filesList) |
|
133 |
end; |
|
134 |
||
135 |
||
136 |
function getTeamsList: PPChar; cdecl; |
|
137 |
var i, t, l: Longword; |
|
138 |
team: PTeam; |
|
139 |
begin |
|
140 |
if teamsList = nil then |
|
141 |
loadTeams; |
|
142 |
||
143 |
t:= teamsNumber; |
|
144 |
if t >= MAX_TEAM_NAMES then |
|
145 |
t:= MAX_TEAM_NAMES; |
|
146 |
||
147 |
team:= teamsList; |
|
148 |
for i:= 0 to Pred(t) do |
|
149 |
begin |
|
150 |
l:= length(team^.teamName); |
|
151 |
if l >= 255 then l:= 254; |
|
152 |
team^.teamName[l + 1]:= #0; |
|
10442 | 153 |
listOfTeamNames[i]:= @team^.teamName[1]; |
154 |
inc(team) |
|
10440 | 155 |
end; |
156 |
||
157 |
listOfTeamNames[t]:= nil; |
|
158 |
||
159 |
getTeamsList:= listOfTeamNames |
|
160 |
end; |
|
161 |
||
10446 | 162 |
function teamByName(s: shortstring): PTeam; |
163 |
var i: Longword; |
|
164 |
team: PTeam; |
|
165 |
begin |
|
166 |
team:= teamsList; |
|
167 |
i:= 0; |
|
168 |
while (i < teamsNumber) and (team^.teamName <> s) do |
|
169 |
begin |
|
170 |
inc(team); |
|
171 |
inc(i) |
|
172 |
end; |
|
173 |
||
174 |
if i < teamsNumber then teamByName:= team else teamByName:= nil |
|
175 |
end; |
|
10440 | 176 |
|
177 |
procedure freeTeamsList; |
|
178 |
begin |
|
179 |
if teamsList <> nil then |
|
180 |
FreeMem(teamsList, sizeof(teamsList^) * teamsNumber) |
|
181 |
end; |
|
182 |
||
10434
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
183 |
end. |