author | unc0rr |
Thu, 03 Dec 2015 23:59:06 +0300 | |
branch | qmlfrontend |
changeset 11447 | 6b04a266feee |
parent 11442 | 6e641b5453f9 |
child 11449 | 91f8c6ff5bab |
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 |
10612 | 53 |
ipcToEngine('eaddhh ' + inttostr(botLevel) + ' 100 hog');// + hedgehogs[i].name); |
54 |
//ipcToEngine('ehat ' + hedgehogs[i].hat); |
|
10434
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 |
|
11447 | 82 |
team.grave:= midStr(l, 7) |
10440 | 83 |
else if copy(l, 1, 5) = 'Fort=' then |
11447 | 84 |
team.fort:= midStr(l, 6) |
10440 | 85 |
else if copy(l, 1, 5) = 'Flag=' then |
86 |
team.flag:= midStr(l, 6) |
|
87 |
end; |
|
88 |
// TODO: load hedgehogs and other stuff |
|
11442 | 89 |
team.botLevel:= 0 |
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^); |
|
109 |
l:= length(s); |
|
10442 | 110 |
if (l > 4) and (copy(s, l - 3, 4) = '.hwt') then inc(teamsNumber); |
111 |
inc(tmp) |
|
10440 | 112 |
end; |
113 |
||
114 |
// TODO: no teams at all? |
|
115 |
teamsList:= GetMem(sizeof(teamsList^) * teamsNumber); |
|
116 |
||
117 |
team:= teamsList; |
|
118 |
tmp:= filesList; |
|
119 |
while tmp^ <> nil do |
|
120 |
begin |
|
121 |
s:= shortstring(tmp^); |
|
122 |
l:= length(s); |
|
123 |
if (l > 4) and (copy(s, l - 3, 4) = '.hwt') then |
|
124 |
begin |
|
125 |
loadTeam(team^, '/Config/Teams/' + s); |
|
126 |
inc(team) |
|
127 |
end; |
|
10442 | 128 |
inc(tmp) |
10440 | 129 |
end; |
130 |
||
131 |
pfsFreeList(filesList) |
|
132 |
end; |
|
133 |
||
134 |
||
135 |
function getTeamsList: PPChar; cdecl; |
|
136 |
var i, t, l: Longword; |
|
137 |
team: PTeam; |
|
138 |
begin |
|
139 |
if teamsList = nil then |
|
140 |
loadTeams; |
|
141 |
||
142 |
t:= teamsNumber; |
|
143 |
if t >= MAX_TEAM_NAMES then |
|
144 |
t:= MAX_TEAM_NAMES; |
|
145 |
||
146 |
team:= teamsList; |
|
147 |
for i:= 0 to Pred(t) do |
|
148 |
begin |
|
149 |
l:= length(team^.teamName); |
|
150 |
if l >= 255 then l:= 254; |
|
151 |
team^.teamName[l + 1]:= #0; |
|
10442 | 152 |
listOfTeamNames[i]:= @team^.teamName[1]; |
153 |
inc(team) |
|
10440 | 154 |
end; |
155 |
||
156 |
listOfTeamNames[t]:= nil; |
|
157 |
||
158 |
getTeamsList:= listOfTeamNames |
|
159 |
end; |
|
160 |
||
10446 | 161 |
function teamByName(s: shortstring): PTeam; |
162 |
var i: Longword; |
|
163 |
team: PTeam; |
|
164 |
begin |
|
165 |
team:= teamsList; |
|
166 |
i:= 0; |
|
167 |
while (i < teamsNumber) and (team^.teamName <> s) do |
|
168 |
begin |
|
169 |
inc(team); |
|
170 |
inc(i) |
|
171 |
end; |
|
172 |
||
173 |
if i < teamsNumber then teamByName:= team else teamByName:= nil |
|
174 |
end; |
|
10440 | 175 |
|
176 |
procedure freeTeamsList; |
|
177 |
begin |
|
178 |
if teamsList <> nil then |
|
179 |
FreeMem(teamsList, sizeof(teamsList^) * teamsNumber) |
|
180 |
end; |
|
181 |
||
10434
1614b13ad35e
Themes model, also add some files I forgot to add previously
unc0rr
parents:
diff
changeset
|
182 |
end. |