author | smxx |
Thu, 04 Feb 2010 20:49:23 +0000 | |
changeset 2749 | 0d24a4a9a82a |
parent 2747 | 7889a3a9724f |
child 2758 | 033aa644578f |
permissions | -rw-r--r-- |
4 | 1 |
(* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
883 | 3 |
* Copyright (c) 2004-2008 Andrey Korotaev <unC0Rr@gmail.com> |
4 | 4 |
* |
183 | 5 |
* This program is free software; you can redistribute it and/or modify |
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
4 | 8 |
* |
183 | 9 |
* This program is distributed in the hope that it will be useful, |
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
4 | 13 |
* |
183 | 14 |
* You should have received a copy of the GNU General Public License |
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
4 | 17 |
*) |
18 |
||
2599 | 19 |
{$INCLUDE "options.inc"} |
2587
0dfa56a8513c
fix a segfault in the iphone simulator by moving options.inc at the beginning of the file
koda
parents:
2586
diff
changeset
|
20 |
|
4 | 21 |
unit uTeams; |
22 |
interface |
|
2376 | 23 |
uses SDLh, uConsts, uKeys, uGears, uRandom, uFloat, uStats, uVisualGears, |
2152 | 24 |
{$IFDEF GLES11} |
1906 | 25 |
gles11, |
26 |
{$ELSE} |
|
27 |
GL, |
|
28 |
{$ENDIF} |
|
29 |
uSound; |
|
534 | 30 |
|
31 |
type PHHAmmo = ^THHAmmo; |
|
1299 | 32 |
THHAmmo = array[0..cMaxSlotIndex, 0..cMaxSlotAmmoIndex] of TAmmo; |
534 | 33 |
|
1299 | 34 |
PHedgehog = ^THedgehog; |
35 |
PTeam = ^TTeam; |
|
36 |
PClan = ^TClan; |
|
2376 | 37 |
|
1299 | 38 |
THedgehog = record |
39 |
Name: string[MAXNAMELEN]; |
|
40 |
Gear: PGear; |
|
2042
905c554d62e6
Move Speech to visual gears. This checkin CRASHES on deletion of visual gear outside the doStep
nemo
parents:
2040
diff
changeset
|
41 |
SpeechGear: PVisualGear; |
1299 | 42 |
NameTagTex, |
43 |
HealthTagTex, |
|
44 |
HatTex: PTexture; |
|
45 |
Ammo: PHHAmmo; |
|
46 |
AmmoStore: Longword; |
|
47 |
CurSlot, CurAmmo: LongWord; |
|
48 |
Team: PTeam; |
|
2608 | 49 |
MultiShootAttacks: Longword; |
1299 | 50 |
visStepPos: LongWord; |
51 |
BotLevel : LongWord; // 0 - Human player |
|
52 |
HatVisibility: GLfloat; |
|
53 |
stats: TStatistics; |
|
54 |
Hat: String; |
|
2726 | 55 |
King: boolean; // Flag for a bunch of hedgehog attributes |
1299 | 56 |
end; |
2376 | 57 |
|
1299 | 58 |
TTeam = record |
59 |
Clan: PClan; |
|
60 |
TeamName: string[MAXNAMELEN]; |
|
61 |
ExtDriven: boolean; |
|
62 |
Binds: TBinds; |
|
63 |
Hedgehogs: array[0..cMaxHHIndex] of THedgehog; |
|
64 |
CurrHedgehog: LongWord; |
|
65 |
NameTagTex: PTexture; |
|
66 |
CrosshairTex, |
|
67 |
GraveTex, |
|
2747 | 68 |
HealthTex, |
69 |
FlagTex: PTexture; |
|
70 |
Flag: string; |
|
1299 | 71 |
GraveName: string; |
72 |
FortName: string; |
|
73 |
TeamHealth: LongInt; |
|
74 |
TeamHealthBarWidth, |
|
75 |
NewTeamHealthBarWidth: LongInt; |
|
76 |
DrawHealthY: LongInt; |
|
77 |
AttackBar: LongWord; |
|
78 |
HedgehogsNumber: Longword; |
|
1351
aa7aefec5c1b
Add partial implementation of handling disconnects while playing via network
unc0rr
parents:
1299
diff
changeset
|
79 |
hasGone: boolean; |
1654 | 80 |
voicepack: PVoicepack; |
1299 | 81 |
end; |
2376 | 82 |
|
1299 | 83 |
TClan = record |
84 |
Color: Longword; |
|
85 |
Teams: array[0..Pred(cMaxTeams)] of PTeam; |
|
86 |
TeamsNumber: Longword; |
|
87 |
CurrTeam: LongWord; |
|
88 |
ClanHealth: LongInt; |
|
89 |
ClanIndex: LongInt; |
|
90 |
TurnNumber: LongWord; |
|
91 |
end; |
|
4 | 92 |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
93 |
var CurrentTeam: PTeam; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
94 |
PreviousTeam: PTeam; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
95 |
CurrentHedgehog: PHedgehog; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
96 |
TeamsArray: array[0..Pred(cMaxTeams)] of PTeam; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
97 |
TeamsCount: Longword; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
98 |
ClansArray: array[0..Pred(cMaxTeams)] of PClan; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
99 |
ClansCount: Longword; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
100 |
LocalClan: Longword; // first non-bot, non-extdriven clan |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
101 |
CurMinAngle, CurMaxAngle: Longword; |
4 | 102 |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
103 |
procedure init_uTeams; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
104 |
procedure free_uTeams; |
1058
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
105 |
function AddTeam(TeamColor: Longword): PTeam; |
4 | 106 |
procedure SwitchHedgehog; |
1058
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
107 |
procedure AfterSwitchHedgehog; |
4 | 108 |
procedure InitTeams; |
109 |
function TeamSize(p: PTeam): Longword; |
|
47 | 110 |
procedure RecountTeamHealth(team: PTeam); |
72 | 111 |
procedure RestoreTeamsFromSave; |
1058
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
112 |
function CheckForWin: boolean; |
1351
aa7aefec5c1b
Add partial implementation of handling disconnects while playing via network
unc0rr
parents:
1299
diff
changeset
|
113 |
procedure TeamGone(s: shortstring); |
2040 | 114 |
procedure TeamGoneEffect(var Team: TTeam); |
4 | 115 |
|
116 |
implementation |
|
2042
905c554d62e6
Move Speech to visual gears. This checkin CRASHES on deletion of visual gear outside the doStep
nemo
parents:
2040
diff
changeset
|
117 |
uses uMisc, uWorld, uAI, uLocale, uConsole, uAmmos, uChat; |
371 | 118 |
const MaxTeamHealth: LongInt = 0; |
4 | 119 |
|
92
0c359a7a2356
- Fix win message to appear only after all hedgehogs death
unc0rr
parents:
89
diff
changeset
|
120 |
function CheckForWin: boolean; |
576 | 121 |
var AliveClan: PClan; |
306 | 122 |
s: shortstring; |
1011 | 123 |
t, AliveCount, i, j: LongInt; |
83 | 124 |
begin |
548 | 125 |
AliveCount:= 0; |
549 | 126 |
for t:= 0 to Pred(ClansCount) do |
1299 | 127 |
if ClansArray[t]^.ClanHealth > 0 then |
128 |
begin |
|
129 |
inc(AliveCount); |
|
130 |
AliveClan:= ClansArray[t] |
|
131 |
end; |
|
548 | 132 |
|
1299 | 133 |
if (AliveCount > 1) |
134 |
or ((AliveCount = 1) and ((GameFlags and gfOneClanMode) <> 0)) then exit(false); |
|
351 | 135 |
CheckForWin:= true; |
83 | 136 |
|
137 |
TurnTimeLeft:= 0; |
|
548 | 138 |
if AliveCount = 0 then |
1011 | 139 |
begin // draw |
2619 | 140 |
AddCaption(trmsg[sidDraw], cWhiteColor, capgrpGameState); |
1011 | 141 |
SendStat(siGameResult, trmsg[sidDraw]); |
142 |
AddGear(0, 0, gtATFinishGame, 0, _0, _0, 3000) |
|
143 |
end else // win |
|
144 |
with AliveClan^ do |
|
145 |
begin |
|
146 |
if TeamsNumber = 1 then |
|
147 |
s:= Format(trmsg[sidWinner], Teams[0]^.TeamName) // team wins |
|
148 |
else |
|
149 |
s:= Format(trmsg[sidWinner], Teams[0]^.TeamName); // clan wins |
|
549 | 150 |
|
1011 | 151 |
for j:= 0 to Pred(TeamsNumber) do |
152 |
with Teams[j]^ do |
|
153 |
for i:= 0 to cMaxHHIndex do |
|
154 |
with Hedgehogs[i] do |
|
155 |
if (Gear <> nil) then |
|
156 |
Gear^.State:= gstWinner; |
|
2376 | 157 |
|
2619 | 158 |
AddCaption(s, cWhiteColor, capgrpGameState); |
1011 | 159 |
SendStat(siGameResult, s); |
160 |
AddGear(0, 0, gtATFinishGame, 0, _0, _0, 3000) |
|
161 |
end; |
|
307 | 162 |
SendStats |
83 | 163 |
end; |
164 |
||
4 | 165 |
procedure SwitchHedgehog; |
551 | 166 |
var c: LongWord; |
552 | 167 |
PrevHH, PrevTeam: LongWord; |
4 | 168 |
begin |
169 |
TargetPoint.X:= NoPointX; |
|
89 | 170 |
TryDo(CurrentTeam <> nil, 'nil Team', true); |
1678 | 171 |
PreviousTeam:= CurrentTeam; |
547 | 172 |
|
944 | 173 |
with CurrentHedgehog^ do |
1299 | 174 |
if Gear <> nil then |
175 |
begin |
|
2608 | 176 |
MultiShootAttacks:= 0; |
1299 | 177 |
Gear^.Message:= 0; |
178 |
Gear^.Z:= cHHZ; |
|
179 |
RemoveGearFromList(Gear); |
|
180 |
InsertGearToList(Gear) |
|
181 |
end; |
|
4 | 182 |
|
550 | 183 |
c:= CurrentTeam^.Clan^.ClanIndex; |
4 | 184 |
repeat |
1058
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
185 |
inc(c); |
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
186 |
if c = ClansCount then |
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
187 |
begin |
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
188 |
inc(TotalRounds); |
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
189 |
c:= 0 |
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
190 |
end; |
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
191 |
|
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
192 |
with ClansArray[c]^ do |
1351
aa7aefec5c1b
Add partial implementation of handling disconnects while playing via network
unc0rr
parents:
1299
diff
changeset
|
193 |
begin |
aa7aefec5c1b
Add partial implementation of handling disconnects while playing via network
unc0rr
parents:
1299
diff
changeset
|
194 |
PrevTeam:= CurrTeam; |
1058
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
195 |
repeat |
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
196 |
CurrTeam:= Succ(CurrTeam) mod TeamsNumber; |
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
197 |
CurrentTeam:= Teams[CurrTeam]; |
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
198 |
with CurrentTeam^ do |
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
199 |
begin |
2726 | 200 |
PrevHH:= CurrHedgehog mod HedgehogsNumber; // prevent infinite loop when CurrHedgehog = 7, but HedgehogsNumber < 8 (team is destroyed before its first turn) |
1058
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
201 |
repeat |
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
202 |
CurrHedgehog:= Succ(CurrHedgehog) mod HedgehogsNumber; |
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
203 |
until (Hedgehogs[CurrHedgehog].Gear <> nil) or (CurrHedgehog = PrevHH) |
1299 | 204 |
end |
2040 | 205 |
until (CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear <> nil) or (PrevTeam = CurrTeam); |
1351
aa7aefec5c1b
Add partial implementation of handling disconnects while playing via network
unc0rr
parents:
1299
diff
changeset
|
206 |
end |
2040 | 207 |
until (CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear <> nil); |
83 | 208 |
|
1058
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
209 |
CurrentHedgehog:= @(CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog]) |
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
210 |
end; |
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
211 |
|
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
212 |
procedure AfterSwitchHedgehog; |
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
213 |
var g: PGear; |
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
214 |
begin |
2431
23242609c44b
Real fix to ammo slot overflow (bug triggered by r2411 fix)
unc0rr
parents:
2376
diff
changeset
|
215 |
inc(CurrentTeam^.Clan^.TurnNumber); |
23242609c44b
Real fix to ammo slot overflow (bug triggered by r2411 fix)
unc0rr
parents:
2376
diff
changeset
|
216 |
|
1922 | 217 |
SwitchNotHeldAmmo(CurrentHedgehog^); |
2431
23242609c44b
Real fix to ammo slot overflow (bug triggered by r2411 fix)
unc0rr
parents:
2376
diff
changeset
|
218 |
|
602 | 219 |
with CurrentHedgehog^ do |
1299 | 220 |
begin |
221 |
with Gear^ do |
|
222 |
begin |
|
223 |
Z:= cCurrHHZ; |
|
224 |
State:= gstHHDriven; |
|
225 |
Active:= true |
|
226 |
end; |
|
227 |
RemoveGearFromList(Gear); |
|
228 |
InsertGearToList(Gear); |
|
229 |
FollowGear:= Gear |
|
230 |
end; |
|
941
b5222ddafe1f
- Fix bug with picking up ammos from cases, when total ammo count may become more than AMMO_INFINITE
unc0rr
parents:
927
diff
changeset
|
231 |
|
4 | 232 |
ResetKbd; |
351 | 233 |
|
234 |
cWindSpeed:= rndSign(GetRandom * cMaxWindSpeed); |
|
498 | 235 |
g:= AddGear(0, 0, gtATSmoothWindCh, 0, _0, _0, 1); |
351 | 236 |
g^.Tag:= hwRound(cWindSpeed * 72 / cMaxWindSpeed); |
4 | 237 |
{$IFDEF DEBUGFILE}AddFileLog('Wind = '+FloatToStr(cWindSpeed));{$ENDIF} |
602 | 238 |
ApplyAmmoChanges(CurrentHedgehog^); |
800 | 239 |
|
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2715
diff
changeset
|
240 |
{$IFNDEF IPHONEOS} |
1650
a65681cc27c2
Don't fallback to default binds set when switching to remotely driven team
unc0rr
parents:
1495
diff
changeset
|
241 |
if not CurrentTeam^.ExtDriven then SetBinds(CurrentTeam^.Binds); |
2579 | 242 |
{$ENDIF} |
1650
a65681cc27c2
Don't fallback to default binds set when switching to remotely driven team
unc0rr
parents:
1495
diff
changeset
|
243 |
|
176 | 244 |
bShowFinger:= true; |
800 | 245 |
|
801 | 246 |
if (CurrentTeam^.ExtDriven or (CurrentHedgehog^.BotLevel > 0)) then |
2745 | 247 |
PlaySound(sndIllGetYou, CurrentTeam^.voicepack) |
801 | 248 |
else |
2745 | 249 |
PlaySound(sndYesSir, CurrentTeam^.voicepack); |
800 | 250 |
|
4 | 251 |
TurnTimeLeft:= cHedgehogTurnTime |
252 |
end; |
|
253 |
||
549 | 254 |
function AddTeam(TeamColor: Longword): PTeam; |
2695 | 255 |
var team: PTeam; |
549 | 256 |
c: LongInt; |
4 | 257 |
begin |
1170 | 258 |
TryDo(TeamsCount < cMaxTeams, 'Too many teams', true); |
2695 | 259 |
New(team); |
260 |
TryDo(team <> nil, 'AddTeam: team = nil', true); |
|
261 |
FillChar(team^, sizeof(TTeam), 0); |
|
262 |
team^.AttackBar:= 2; |
|
263 |
team^.CurrHedgehog:= cMaxHHIndex; |
|
2747 | 264 |
team^.Flag:= 'hedgewars'; |
547 | 265 |
|
2695 | 266 |
TeamsArray[TeamsCount]:= team; |
547 | 267 |
inc(TeamsCount); |
268 |
||
549 | 269 |
c:= Pred(ClansCount); |
270 |
while (c >= 0) and (ClansArray[c]^.Color <> TeamColor) do dec(c); |
|
271 |
if c < 0 then |
|
272 |
begin |
|
2695 | 273 |
new(team^.Clan); |
274 |
FillChar(team^.Clan^, sizeof(TClan), 0); |
|
275 |
ClansArray[ClansCount]:= team^.Clan; |
|
549 | 276 |
inc(ClansCount); |
2695 | 277 |
with team^.Clan^ do |
549 | 278 |
begin |
550 | 279 |
ClanIndex:= Pred(ClansCount); |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
280 |
Color:= TeamColor |
549 | 281 |
end |
282 |
end else |
|
283 |
begin |
|
2695 | 284 |
team^.Clan:= ClansArray[c]; |
549 | 285 |
end; |
286 |
||
2695 | 287 |
with team^.Clan^ do |
549 | 288 |
begin |
2695 | 289 |
Teams[TeamsNumber]:= team; |
549 | 290 |
inc(TeamsNumber) |
291 |
end; |
|
292 |
||
2695 | 293 |
CurrentTeam:= team; |
294 |
AddTeam:= team; |
|
4 | 295 |
end; |
296 |
||
47 | 297 |
procedure RecountAllTeamsHealth; |
547 | 298 |
var t: LongInt; |
2376 | 299 |
begin |
547 | 300 |
for t:= 0 to Pred(TeamsCount) do |
301 |
RecountTeamHealth(TeamsArray[t]) |
|
47 | 302 |
end; |
303 |
||
304 |
procedure InitTeams; |
|
547 | 305 |
var i, t: LongInt; |
371 | 306 |
th: LongInt; |
47 | 307 |
begin |
2726 | 308 |
|
309 |
// Some initial King buffs |
|
310 |
if (GameFlags and gfKing) <> 0 then |
|
311 |
for i:= 0 to Pred(ClansCount) do |
|
312 |
begin |
|
313 |
with ClansArray[i]^.Teams[0]^.Hedgehogs[0] do |
|
314 |
begin |
|
315 |
King:= true; |
|
316 |
Hat:= 'crown'; |
|
317 |
Gear^.Health:= hwRound(int2hwFloat(Gear^.Health)*_1_5); |
|
318 |
end |
|
319 |
end; |
|
320 |
||
547 | 321 |
for t:= 0 to Pred(TeamsCount) do |
322 |
with TeamsArray[t]^ do |
|
47 | 323 |
begin |
2124 | 324 |
if (not ExtDriven) and (Hedgehogs[0].BotLevel = 0) then |
325 |
LocalClan:= Clan^.ClanIndex + 1; |
|
47 | 326 |
th:= 0; |
4 | 327 |
for i:= 0 to cMaxHHIndex do |
547 | 328 |
if Hedgehogs[i].Gear <> nil then |
329 |
inc(th, Hedgehogs[i].Gear^.Health); |
|
47 | 330 |
if th > MaxTeamHealth then MaxTeamHealth:= th; |
4 | 331 |
end; |
2726 | 332 |
|
47 | 333 |
RecountAllTeamsHealth |
4 | 334 |
end; |
335 |
||
336 |
function TeamSize(p: PTeam): Longword; |
|
2695 | 337 |
var i, value: Longword; |
4 | 338 |
begin |
2695 | 339 |
value:= 0; |
4 | 340 |
for i:= 0 to cMaxHHIndex do |
2695 | 341 |
if p^.Hedgehogs[i].Gear <> nil then inc(value); |
342 |
TeamSize:= value; |
|
4 | 343 |
end; |
344 |
||
549 | 345 |
procedure RecountClanHealth(clan: PClan); |
346 |
var i: LongInt; |
|
347 |
begin |
|
348 |
with clan^ do |
|
349 |
begin |
|
350 |
ClanHealth:= 0; |
|
351 |
for i:= 0 to Pred(TeamsNumber) do |
|
352 |
inc(ClanHealth, Teams[i]^.TeamHealth) |
|
353 |
end |
|
354 |
end; |
|
355 |
||
47 | 356 |
procedure RecountTeamHealth(team: PTeam); |
371 | 357 |
var i: LongInt; |
47 | 358 |
begin |
359 |
with team^ do |
|
1352
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1351
diff
changeset
|
360 |
begin |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1351
diff
changeset
|
361 |
NewTeamHealthBarWidth:= 0; |
2376 | 362 |
|
1352
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1351
diff
changeset
|
363 |
if not hasGone then |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1351
diff
changeset
|
364 |
for i:= 0 to cMaxHHIndex do |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1351
diff
changeset
|
365 |
if Hedgehogs[i].Gear <> nil then |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1351
diff
changeset
|
366 |
inc(NewTeamHealthBarWidth, Hedgehogs[i].Gear^.Health); |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1351
diff
changeset
|
367 |
|
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1351
diff
changeset
|
368 |
TeamHealth:= NewTeamHealthBarWidth; |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1351
diff
changeset
|
369 |
if NewTeamHealthBarWidth > MaxTeamHealth then |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1351
diff
changeset
|
370 |
begin |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1351
diff
changeset
|
371 |
MaxTeamHealth:= NewTeamHealthBarWidth; |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1351
diff
changeset
|
372 |
RecountAllTeamsHealth; |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1351
diff
changeset
|
373 |
end else NewTeamHealthBarWidth:= (NewTeamHealthBarWidth * cTeamHealthWidth) div MaxTeamHealth |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1351
diff
changeset
|
374 |
end; |
549 | 375 |
|
376 |
RecountClanHealth(team^.Clan); |
|
377 |
||
2005 | 378 |
AddVisualGear(0, 0, vgtTeamHealthSorter) |
47 | 379 |
end; |
380 |
||
72 | 381 |
procedure RestoreTeamsFromSave; |
547 | 382 |
var t: LongInt; |
72 | 383 |
begin |
547 | 384 |
for t:= 0 to Pred(TeamsCount) do |
385 |
TeamsArray[t]^.ExtDriven:= false |
|
72 | 386 |
end; |
387 |
||
1351
aa7aefec5c1b
Add partial implementation of handling disconnects while playing via network
unc0rr
parents:
1299
diff
changeset
|
388 |
procedure TeamGone(s: shortstring); |
2040 | 389 |
var t: LongInt; |
1351
aa7aefec5c1b
Add partial implementation of handling disconnects while playing via network
unc0rr
parents:
1299
diff
changeset
|
390 |
begin |
1362 | 391 |
t:= 0; |
1356 | 392 |
while (t < cMaxTeams) |
393 |
and (TeamsArray[t] <> nil) |
|
394 |
and (TeamsArray[t]^.TeamName <> s) do inc(t); |
|
395 |
if (t = cMaxTeams) or (TeamsArray[t] = nil) then exit; |
|
1351
aa7aefec5c1b
Add partial implementation of handling disconnects while playing via network
unc0rr
parents:
1299
diff
changeset
|
396 |
|
1356 | 397 |
with TeamsArray[t]^ do |
1351
aa7aefec5c1b
Add partial implementation of handling disconnects while playing via network
unc0rr
parents:
1299
diff
changeset
|
398 |
begin |
1495 | 399 |
AddChatString('** '+ TeamName + ' is gone'); |
1351
aa7aefec5c1b
Add partial implementation of handling disconnects while playing via network
unc0rr
parents:
1299
diff
changeset
|
400 |
hasGone:= true |
1355 | 401 |
end; |
2376 | 402 |
|
1363 | 403 |
RecountTeamHealth(TeamsArray[t]) |
1351
aa7aefec5c1b
Add partial implementation of handling disconnects while playing via network
unc0rr
parents:
1299
diff
changeset
|
404 |
end; |
aa7aefec5c1b
Add partial implementation of handling disconnects while playing via network
unc0rr
parents:
1299
diff
changeset
|
405 |
|
2040 | 406 |
procedure TeamGoneEffect(var Team: TTeam); |
407 |
var i: LongInt; |
|
408 |
begin |
|
409 |
with Team do |
|
410 |
for i:= 0 to cMaxHHIndex do |
|
411 |
with Hedgehogs[i] do |
|
412 |
if Gear <> nil then |
|
413 |
Gear^.Damage:= Gear^.Health |
|
414 |
end; |
|
415 |
||
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
416 |
procedure init_uTeams; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
417 |
begin |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
418 |
CurrentTeam:= nil; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
419 |
PreviousTeam:= nil; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
420 |
CurrentHedgehog:= nil; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
421 |
TeamsCount:= 0; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
422 |
ClansCount:= 0; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
423 |
LocalClan:= 0; // first non-bot, non-extdriven clan |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
424 |
end; |
4 | 425 |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
426 |
procedure free_uTeams; |
2715
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2704
diff
changeset
|
427 |
var i: LongWord; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
428 |
begin |
2715
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2704
diff
changeset
|
429 |
for i:= 0 to Pred(TeamsCount) do Dispose(TeamsArray[i]); |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2704
diff
changeset
|
430 |
for i:= 0 to Pred(ClansCount) do Dispose(ClansArray[i]); |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2704
diff
changeset
|
431 |
TeamsCount:= 0; |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2704
diff
changeset
|
432 |
ClansCount:= 0 |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
433 |
end; |
4 | 434 |
|
435 |
end. |