author | smxx |
Wed, 03 Feb 2010 13:02:28 +0000 | |
changeset 2742 | 21c0d2e69753 |
parent 2730 | f56592281526 |
child 2745 | 11fce231f24a |
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, |
|
68 |
HealthTex: PTexture; |
|
69 |
GraveName: string; |
|
70 |
FortName: string; |
|
71 |
TeamHealth: LongInt; |
|
72 |
TeamHealthBarWidth, |
|
73 |
NewTeamHealthBarWidth: LongInt; |
|
74 |
DrawHealthY: LongInt; |
|
75 |
AttackBar: LongWord; |
|
76 |
HedgehogsNumber: Longword; |
|
1351
aa7aefec5c1b
Add partial implementation of handling disconnects while playing via network
unc0rr
parents:
1299
diff
changeset
|
77 |
hasGone: boolean; |
1654 | 78 |
voicepack: PVoicepack; |
1299 | 79 |
end; |
2376 | 80 |
|
1299 | 81 |
TClan = record |
82 |
Color: Longword; |
|
83 |
Teams: array[0..Pred(cMaxTeams)] of PTeam; |
|
84 |
TeamsNumber: Longword; |
|
85 |
CurrTeam: LongWord; |
|
86 |
ClanHealth: LongInt; |
|
87 |
ClanIndex: LongInt; |
|
88 |
TurnNumber: LongWord; |
|
89 |
end; |
|
4 | 90 |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
91 |
var CurrentTeam: PTeam; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
92 |
PreviousTeam: PTeam; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
93 |
CurrentHedgehog: PHedgehog; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
94 |
TeamsArray: array[0..Pred(cMaxTeams)] of PTeam; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
95 |
TeamsCount: Longword; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
96 |
ClansArray: array[0..Pred(cMaxTeams)] of PClan; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
97 |
ClansCount: Longword; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
98 |
LocalClan: Longword; // first non-bot, non-extdriven clan |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
99 |
CurMinAngle, CurMaxAngle: Longword; |
4 | 100 |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
101 |
procedure init_uTeams; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
102 |
procedure free_uTeams; |
1058
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
103 |
function AddTeam(TeamColor: Longword): PTeam; |
4 | 104 |
procedure SwitchHedgehog; |
1058
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
105 |
procedure AfterSwitchHedgehog; |
4 | 106 |
procedure InitTeams; |
107 |
function TeamSize(p: PTeam): Longword; |
|
47 | 108 |
procedure RecountTeamHealth(team: PTeam); |
72 | 109 |
procedure RestoreTeamsFromSave; |
1058
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
110 |
function CheckForWin: boolean; |
1351
aa7aefec5c1b
Add partial implementation of handling disconnects while playing via network
unc0rr
parents:
1299
diff
changeset
|
111 |
procedure TeamGone(s: shortstring); |
2040 | 112 |
procedure TeamGoneEffect(var Team: TTeam); |
4 | 113 |
|
114 |
implementation |
|
2042
905c554d62e6
Move Speech to visual gears. This checkin CRASHES on deletion of visual gear outside the doStep
nemo
parents:
2040
diff
changeset
|
115 |
uses uMisc, uWorld, uAI, uLocale, uConsole, uAmmos, uChat; |
371 | 116 |
const MaxTeamHealth: LongInt = 0; |
4 | 117 |
|
92
0c359a7a2356
- Fix win message to appear only after all hedgehogs death
unc0rr
parents:
89
diff
changeset
|
118 |
function CheckForWin: boolean; |
576 | 119 |
var AliveClan: PClan; |
306 | 120 |
s: shortstring; |
1011 | 121 |
t, AliveCount, i, j: LongInt; |
83 | 122 |
begin |
548 | 123 |
AliveCount:= 0; |
549 | 124 |
for t:= 0 to Pred(ClansCount) do |
1299 | 125 |
if ClansArray[t]^.ClanHealth > 0 then |
126 |
begin |
|
127 |
inc(AliveCount); |
|
128 |
AliveClan:= ClansArray[t] |
|
129 |
end; |
|
548 | 130 |
|
1299 | 131 |
if (AliveCount > 1) |
132 |
or ((AliveCount = 1) and ((GameFlags and gfOneClanMode) <> 0)) then exit(false); |
|
351 | 133 |
CheckForWin:= true; |
83 | 134 |
|
135 |
TurnTimeLeft:= 0; |
|
548 | 136 |
if AliveCount = 0 then |
1011 | 137 |
begin // draw |
2619 | 138 |
AddCaption(trmsg[sidDraw], cWhiteColor, capgrpGameState); |
1011 | 139 |
SendStat(siGameResult, trmsg[sidDraw]); |
140 |
AddGear(0, 0, gtATFinishGame, 0, _0, _0, 3000) |
|
141 |
end else // win |
|
142 |
with AliveClan^ do |
|
143 |
begin |
|
144 |
if TeamsNumber = 1 then |
|
145 |
s:= Format(trmsg[sidWinner], Teams[0]^.TeamName) // team wins |
|
146 |
else |
|
147 |
s:= Format(trmsg[sidWinner], Teams[0]^.TeamName); // clan wins |
|
549 | 148 |
|
1011 | 149 |
for j:= 0 to Pred(TeamsNumber) do |
150 |
with Teams[j]^ do |
|
151 |
for i:= 0 to cMaxHHIndex do |
|
152 |
with Hedgehogs[i] do |
|
153 |
if (Gear <> nil) then |
|
154 |
Gear^.State:= gstWinner; |
|
2376 | 155 |
|
2619 | 156 |
AddCaption(s, cWhiteColor, capgrpGameState); |
1011 | 157 |
SendStat(siGameResult, s); |
158 |
AddGear(0, 0, gtATFinishGame, 0, _0, _0, 3000) |
|
159 |
end; |
|
307 | 160 |
SendStats |
83 | 161 |
end; |
162 |
||
4 | 163 |
procedure SwitchHedgehog; |
551 | 164 |
var c: LongWord; |
552 | 165 |
PrevHH, PrevTeam: LongWord; |
4 | 166 |
begin |
167 |
TargetPoint.X:= NoPointX; |
|
89 | 168 |
TryDo(CurrentTeam <> nil, 'nil Team', true); |
1678 | 169 |
PreviousTeam:= CurrentTeam; |
547 | 170 |
|
944 | 171 |
with CurrentHedgehog^ do |
1299 | 172 |
if Gear <> nil then |
173 |
begin |
|
2608 | 174 |
MultiShootAttacks:= 0; |
1299 | 175 |
Gear^.Message:= 0; |
176 |
Gear^.Z:= cHHZ; |
|
177 |
RemoveGearFromList(Gear); |
|
178 |
InsertGearToList(Gear) |
|
179 |
end; |
|
4 | 180 |
|
550 | 181 |
c:= CurrentTeam^.Clan^.ClanIndex; |
4 | 182 |
repeat |
1058
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
183 |
inc(c); |
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
184 |
if c = ClansCount then |
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
185 |
begin |
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
186 |
inc(TotalRounds); |
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
187 |
c:= 0 |
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
188 |
end; |
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
189 |
|
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
190 |
with ClansArray[c]^ do |
1351
aa7aefec5c1b
Add partial implementation of handling disconnects while playing via network
unc0rr
parents:
1299
diff
changeset
|
191 |
begin |
aa7aefec5c1b
Add partial implementation of handling disconnects while playing via network
unc0rr
parents:
1299
diff
changeset
|
192 |
PrevTeam:= CurrTeam; |
1058
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
193 |
repeat |
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
194 |
CurrTeam:= Succ(CurrTeam) mod TeamsNumber; |
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
195 |
CurrentTeam:= Teams[CurrTeam]; |
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
196 |
with CurrentTeam^ do |
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
197 |
begin |
2726 | 198 |
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
|
199 |
repeat |
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
200 |
CurrHedgehog:= Succ(CurrHedgehog) mod HedgehogsNumber; |
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
201 |
until (Hedgehogs[CurrHedgehog].Gear <> nil) or (CurrHedgehog = PrevHH) |
1299 | 202 |
end |
2040 | 203 |
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
|
204 |
end |
2040 | 205 |
until (CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear <> nil); |
83 | 206 |
|
1058
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
207 |
CurrentHedgehog:= @(CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog]) |
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
208 |
end; |
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
209 |
|
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
210 |
procedure AfterSwitchHedgehog; |
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
211 |
var g: PGear; |
c53c5c4e7b48
- Proper turns counting, split SwitchHedgehog into two functions
unc0rr
parents:
1011
diff
changeset
|
212 |
begin |
2431
23242609c44b
Real fix to ammo slot overflow (bug triggered by r2411 fix)
unc0rr
parents:
2376
diff
changeset
|
213 |
inc(CurrentTeam^.Clan^.TurnNumber); |
23242609c44b
Real fix to ammo slot overflow (bug triggered by r2411 fix)
unc0rr
parents:
2376
diff
changeset
|
214 |
|
1922 | 215 |
SwitchNotHeldAmmo(CurrentHedgehog^); |
2431
23242609c44b
Real fix to ammo slot overflow (bug triggered by r2411 fix)
unc0rr
parents:
2376
diff
changeset
|
216 |
|
602 | 217 |
with CurrentHedgehog^ do |
1299 | 218 |
begin |
219 |
with Gear^ do |
|
220 |
begin |
|
221 |
Z:= cCurrHHZ; |
|
222 |
State:= gstHHDriven; |
|
223 |
Active:= true |
|
224 |
end; |
|
225 |
RemoveGearFromList(Gear); |
|
226 |
InsertGearToList(Gear); |
|
227 |
FollowGear:= Gear |
|
228 |
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
|
229 |
|
4 | 230 |
ResetKbd; |
351 | 231 |
|
232 |
cWindSpeed:= rndSign(GetRandom * cMaxWindSpeed); |
|
498 | 233 |
g:= AddGear(0, 0, gtATSmoothWindCh, 0, _0, _0, 1); |
351 | 234 |
g^.Tag:= hwRound(cWindSpeed * 72 / cMaxWindSpeed); |
4 | 235 |
{$IFDEF DEBUGFILE}AddFileLog('Wind = '+FloatToStr(cWindSpeed));{$ENDIF} |
602 | 236 |
ApplyAmmoChanges(CurrentHedgehog^); |
800 | 237 |
|
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2715
diff
changeset
|
238 |
{$IFNDEF IPHONEOS} |
1650
a65681cc27c2
Don't fallback to default binds set when switching to remotely driven team
unc0rr
parents:
1495
diff
changeset
|
239 |
if not CurrentTeam^.ExtDriven then SetBinds(CurrentTeam^.Binds); |
2579 | 240 |
{$ENDIF} |
1650
a65681cc27c2
Don't fallback to default binds set when switching to remotely driven team
unc0rr
parents:
1495
diff
changeset
|
241 |
|
176 | 242 |
bShowFinger:= true; |
800 | 243 |
|
801 | 244 |
if (CurrentTeam^.ExtDriven or (CurrentHedgehog^.BotLevel > 0)) then |
1669 | 245 |
PlaySound(sndIllGetYou, false, CurrentTeam^.voicepack) |
801 | 246 |
else |
1669 | 247 |
PlaySound(sndYesSir, false, CurrentTeam^.voicepack); |
800 | 248 |
|
4 | 249 |
TurnTimeLeft:= cHedgehogTurnTime |
250 |
end; |
|
251 |
||
549 | 252 |
function AddTeam(TeamColor: Longword): PTeam; |
2695 | 253 |
var team: PTeam; |
549 | 254 |
c: LongInt; |
4 | 255 |
begin |
1170 | 256 |
TryDo(TeamsCount < cMaxTeams, 'Too many teams', true); |
2695 | 257 |
New(team); |
258 |
TryDo(team <> nil, 'AddTeam: team = nil', true); |
|
259 |
FillChar(team^, sizeof(TTeam), 0); |
|
260 |
team^.AttackBar:= 2; |
|
261 |
team^.CurrHedgehog:= cMaxHHIndex; |
|
547 | 262 |
|
2695 | 263 |
TeamsArray[TeamsCount]:= team; |
547 | 264 |
inc(TeamsCount); |
265 |
||
549 | 266 |
c:= Pred(ClansCount); |
267 |
while (c >= 0) and (ClansArray[c]^.Color <> TeamColor) do dec(c); |
|
268 |
if c < 0 then |
|
269 |
begin |
|
2695 | 270 |
new(team^.Clan); |
271 |
FillChar(team^.Clan^, sizeof(TClan), 0); |
|
272 |
ClansArray[ClansCount]:= team^.Clan; |
|
549 | 273 |
inc(ClansCount); |
2695 | 274 |
with team^.Clan^ do |
549 | 275 |
begin |
550 | 276 |
ClanIndex:= Pred(ClansCount); |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
277 |
Color:= TeamColor |
549 | 278 |
end |
279 |
end else |
|
280 |
begin |
|
2695 | 281 |
team^.Clan:= ClansArray[c]; |
549 | 282 |
end; |
283 |
||
2695 | 284 |
with team^.Clan^ do |
549 | 285 |
begin |
2695 | 286 |
Teams[TeamsNumber]:= team; |
549 | 287 |
inc(TeamsNumber) |
288 |
end; |
|
289 |
||
2695 | 290 |
CurrentTeam:= team; |
291 |
AddTeam:= team; |
|
4 | 292 |
end; |
293 |
||
47 | 294 |
procedure RecountAllTeamsHealth; |
547 | 295 |
var t: LongInt; |
2376 | 296 |
begin |
547 | 297 |
for t:= 0 to Pred(TeamsCount) do |
298 |
RecountTeamHealth(TeamsArray[t]) |
|
47 | 299 |
end; |
300 |
||
301 |
procedure InitTeams; |
|
547 | 302 |
var i, t: LongInt; |
371 | 303 |
th: LongInt; |
47 | 304 |
begin |
2726 | 305 |
|
306 |
// Some initial King buffs |
|
307 |
if (GameFlags and gfKing) <> 0 then |
|
308 |
for i:= 0 to Pred(ClansCount) do |
|
309 |
begin |
|
310 |
with ClansArray[i]^.Teams[0]^.Hedgehogs[0] do |
|
311 |
begin |
|
312 |
King:= true; |
|
313 |
Hat:= 'crown'; |
|
314 |
Gear^.Health:= hwRound(int2hwFloat(Gear^.Health)*_1_5); |
|
315 |
end |
|
316 |
end; |
|
317 |
||
547 | 318 |
for t:= 0 to Pred(TeamsCount) do |
319 |
with TeamsArray[t]^ do |
|
47 | 320 |
begin |
2124 | 321 |
if (not ExtDriven) and (Hedgehogs[0].BotLevel = 0) then |
322 |
LocalClan:= Clan^.ClanIndex + 1; |
|
47 | 323 |
th:= 0; |
4 | 324 |
for i:= 0 to cMaxHHIndex do |
547 | 325 |
if Hedgehogs[i].Gear <> nil then |
326 |
inc(th, Hedgehogs[i].Gear^.Health); |
|
47 | 327 |
if th > MaxTeamHealth then MaxTeamHealth:= th; |
4 | 328 |
end; |
2726 | 329 |
|
47 | 330 |
RecountAllTeamsHealth |
4 | 331 |
end; |
332 |
||
333 |
function TeamSize(p: PTeam): Longword; |
|
2695 | 334 |
var i, value: Longword; |
4 | 335 |
begin |
2695 | 336 |
value:= 0; |
4 | 337 |
for i:= 0 to cMaxHHIndex do |
2695 | 338 |
if p^.Hedgehogs[i].Gear <> nil then inc(value); |
339 |
TeamSize:= value; |
|
4 | 340 |
end; |
341 |
||
549 | 342 |
procedure RecountClanHealth(clan: PClan); |
343 |
var i: LongInt; |
|
344 |
begin |
|
345 |
with clan^ do |
|
346 |
begin |
|
347 |
ClanHealth:= 0; |
|
348 |
for i:= 0 to Pred(TeamsNumber) do |
|
349 |
inc(ClanHealth, Teams[i]^.TeamHealth) |
|
350 |
end |
|
351 |
end; |
|
352 |
||
47 | 353 |
procedure RecountTeamHealth(team: PTeam); |
371 | 354 |
var i: LongInt; |
47 | 355 |
begin |
356 |
with team^ do |
|
1352
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1351
diff
changeset
|
357 |
begin |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1351
diff
changeset
|
358 |
NewTeamHealthBarWidth:= 0; |
2376 | 359 |
|
1352
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1351
diff
changeset
|
360 |
if not hasGone then |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1351
diff
changeset
|
361 |
for i:= 0 to cMaxHHIndex do |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1351
diff
changeset
|
362 |
if Hedgehogs[i].Gear <> nil then |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1351
diff
changeset
|
363 |
inc(NewTeamHealthBarWidth, Hedgehogs[i].Gear^.Health); |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1351
diff
changeset
|
364 |
|
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1351
diff
changeset
|
365 |
TeamHealth:= NewTeamHealthBarWidth; |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1351
diff
changeset
|
366 |
if NewTeamHealthBarWidth > MaxTeamHealth then |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1351
diff
changeset
|
367 |
begin |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1351
diff
changeset
|
368 |
MaxTeamHealth:= NewTeamHealthBarWidth; |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1351
diff
changeset
|
369 |
RecountAllTeamsHealth; |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1351
diff
changeset
|
370 |
end else NewTeamHealthBarWidth:= (NewTeamHealthBarWidth * cTeamHealthWidth) div MaxTeamHealth |
405ad07cf875
Add more support for handling disconnects while playing (not fully tested)
unc0rr
parents:
1351
diff
changeset
|
371 |
end; |
549 | 372 |
|
373 |
RecountClanHealth(team^.Clan); |
|
374 |
||
2005 | 375 |
AddVisualGear(0, 0, vgtTeamHealthSorter) |
47 | 376 |
end; |
377 |
||
72 | 378 |
procedure RestoreTeamsFromSave; |
547 | 379 |
var t: LongInt; |
72 | 380 |
begin |
547 | 381 |
for t:= 0 to Pred(TeamsCount) do |
382 |
TeamsArray[t]^.ExtDriven:= false |
|
72 | 383 |
end; |
384 |
||
1351
aa7aefec5c1b
Add partial implementation of handling disconnects while playing via network
unc0rr
parents:
1299
diff
changeset
|
385 |
procedure TeamGone(s: shortstring); |
2040 | 386 |
var t: LongInt; |
1351
aa7aefec5c1b
Add partial implementation of handling disconnects while playing via network
unc0rr
parents:
1299
diff
changeset
|
387 |
begin |
1362 | 388 |
t:= 0; |
1356 | 389 |
while (t < cMaxTeams) |
390 |
and (TeamsArray[t] <> nil) |
|
391 |
and (TeamsArray[t]^.TeamName <> s) do inc(t); |
|
392 |
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
|
393 |
|
1356 | 394 |
with TeamsArray[t]^ do |
1351
aa7aefec5c1b
Add partial implementation of handling disconnects while playing via network
unc0rr
parents:
1299
diff
changeset
|
395 |
begin |
1495 | 396 |
AddChatString('** '+ TeamName + ' is gone'); |
1351
aa7aefec5c1b
Add partial implementation of handling disconnects while playing via network
unc0rr
parents:
1299
diff
changeset
|
397 |
hasGone:= true |
1355 | 398 |
end; |
2376 | 399 |
|
1363 | 400 |
RecountTeamHealth(TeamsArray[t]) |
1351
aa7aefec5c1b
Add partial implementation of handling disconnects while playing via network
unc0rr
parents:
1299
diff
changeset
|
401 |
end; |
aa7aefec5c1b
Add partial implementation of handling disconnects while playing via network
unc0rr
parents:
1299
diff
changeset
|
402 |
|
2040 | 403 |
procedure TeamGoneEffect(var Team: TTeam); |
404 |
var i: LongInt; |
|
405 |
begin |
|
406 |
with Team do |
|
407 |
for i:= 0 to cMaxHHIndex do |
|
408 |
with Hedgehogs[i] do |
|
409 |
if Gear <> nil then |
|
410 |
Gear^.Damage:= Gear^.Health |
|
411 |
end; |
|
412 |
||
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
413 |
procedure init_uTeams; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
414 |
begin |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
415 |
CurrentTeam:= nil; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
416 |
PreviousTeam:= nil; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
417 |
CurrentHedgehog:= nil; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
418 |
TeamsCount:= 0; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
419 |
ClansCount:= 0; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
420 |
LocalClan:= 0; // first non-bot, non-extdriven clan |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
421 |
end; |
4 | 422 |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
423 |
procedure free_uTeams; |
2715
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2704
diff
changeset
|
424 |
var i: LongWord; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
425 |
begin |
2715
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2704
diff
changeset
|
426 |
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
|
427 |
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
|
428 |
TeamsCount:= 0; |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2704
diff
changeset
|
429 |
ClansCount:= 0 |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2695
diff
changeset
|
430 |
end; |
4 | 431 |
|
432 |
end. |