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