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