author | unc0rr |
Mon, 23 Jun 2008 12:25:59 +0000 | |
changeset 1024 | a6942122c31d |
parent 1011 | 4fe2c4c57d10 |
child 1058 | c53c5c4e7b48 |
permissions | -rw-r--r-- |
4 | 1 |
(* |
2 |
* Hedgewars, a worms-like 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 |
||
19 |
unit uTeams; |
|
20 |
interface |
|
814
7fb4417b7bc1
Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
801
diff
changeset
|
21 |
uses SDLh, uConsts, uKeys, uGears, uRandom, uFloat, uStats; |
4 | 22 |
{$INCLUDE options.inc} |
534 | 23 |
|
24 |
type PHHAmmo = ^THHAmmo; |
|
25 |
THHAmmo = array[0..cMaxSlotIndex, 0..cMaxSlotAmmoIndex] of TAmmo; |
|
26 |
||
4 | 27 |
type PHedgehog = ^THedgehog; |
28 |
PTeam = ^TTeam; |
|
549 | 29 |
PClan = ^TClan; |
4 | 30 |
THedgehog = record |
74 | 31 |
Name: string[MAXNAMELEN]; |
4 | 32 |
Gear: PGear; |
762 | 33 |
NameTagTex: PTexture; |
34 |
HealthTagTex: PTexture; |
|
4 | 35 |
Ammo: PHHAmmo; |
288 | 36 |
AmmoStore: Longword; |
4 | 37 |
CurSlot, CurAmmo: LongWord; |
38 |
Team: PTeam; |
|
39 |
AttacksNum: Longword; |
|
40 |
visStepPos: LongWord; |
|
5 | 41 |
BotLevel : LongWord; // 0 - Human player |
814
7fb4417b7bc1
Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
801
diff
changeset
|
42 |
stats: TStatistics; |
4 | 43 |
end; |
44 |
TTeam = record |
|
549 | 45 |
Clan: PClan; |
74 | 46 |
TeamName: string[MAXNAMELEN]; |
4 | 47 |
ExtDriven: boolean; |
167 | 48 |
Binds: TBinds; |
4 | 49 |
Hedgehogs: array[0..cMaxHHIndex] of THedgehog; |
551 | 50 |
CurrHedgehog: LongWord; |
762 | 51 |
NameTagTex: PTexture; |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
52 |
CrosshairTex, |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
53 |
GraveTex, |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
54 |
HealthTex: PTexture; |
4 | 55 |
GraveName: string; |
56 |
FortName: string; |
|
371 | 57 |
TeamHealth: LongInt; |
557 | 58 |
TeamHealthBarWidth, |
59 |
NewTeamHealthBarWidth: LongInt; |
|
371 | 60 |
DrawHealthY: LongInt; |
4 | 61 |
AttackBar: LongWord; |
550 | 62 |
HedgehogsNumber: Longword; |
4 | 63 |
end; |
549 | 64 |
TClan = record |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
65 |
Color: Longword; |
549 | 66 |
Teams: array[0..Pred(cMaxTeams)] of PTeam; |
67 |
TeamsNumber: Longword; |
|
551 | 68 |
CurrTeam: LongWord; |
549 | 69 |
ClanHealth: LongInt; |
550 | 70 |
ClanIndex: LongInt; |
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
|
71 |
TurnNumber: LongWord; |
549 | 72 |
end; |
4 | 73 |
|
74 |
var CurrentTeam: PTeam = nil; |
|
602 | 75 |
CurrentHedgehog: PHedgehog = nil; |
547 | 76 |
TeamsArray: array[0..Pred(cMaxTeams)] of PTeam; |
77 |
TeamsCount: Longword = 0; |
|
549 | 78 |
ClansArray: array[0..Pred(cMaxTeams)] of PClan; |
79 |
ClansCount: Longword = 0; |
|
304 | 80 |
CurMinAngle, CurMaxAngle: Longword; |
4 | 81 |
|
549 | 82 |
function AddTeam(TeamColor: Longword): PTeam; |
4 | 83 |
procedure SwitchHedgehog; |
84 |
procedure InitTeams; |
|
85 |
function TeamSize(p: PTeam): Longword; |
|
47 | 86 |
procedure RecountTeamHealth(team: PTeam); |
72 | 87 |
procedure RestoreTeamsFromSave; |
92
0c359a7a2356
- Fix win message to appear only after all hedgehogs death
unc0rr
parents:
89
diff
changeset
|
88 |
function CheckForWin: boolean; |
4 | 89 |
|
90 |
implementation |
|
800 | 91 |
uses uMisc, uWorld, uAI, uLocale, uConsole, uAmmos, uSound; |
371 | 92 |
const MaxTeamHealth: LongInt = 0; |
4 | 93 |
|
94 |
procedure FreeTeamsList; forward; |
|
95 |
||
92
0c359a7a2356
- Fix win message to appear only after all hedgehogs death
unc0rr
parents:
89
diff
changeset
|
96 |
function CheckForWin: boolean; |
576 | 97 |
var AliveClan: PClan; |
306 | 98 |
s: shortstring; |
1011 | 99 |
t, AliveCount, i, j: LongInt; |
83 | 100 |
begin |
548 | 101 |
AliveCount:= 0; |
549 | 102 |
for t:= 0 to Pred(ClansCount) do |
103 |
if ClansArray[t]^.ClanHealth > 0 then |
|
548 | 104 |
begin |
105 |
inc(AliveCount); |
|
549 | 106 |
AliveClan:= ClansArray[t] |
548 | 107 |
end; |
108 |
||
601
78a68cc4d846
Special game mode allowing the only clan on map for training mode
unc0rr
parents:
576
diff
changeset
|
109 |
if (AliveCount > 1) or |
78a68cc4d846
Special game mode allowing the only clan on map for training mode
unc0rr
parents:
576
diff
changeset
|
110 |
((AliveCount = 1) and ((GameFlags and gfOneClanMode) <> 0)) then exit(false); |
351 | 111 |
CheckForWin:= true; |
83 | 112 |
|
113 |
TurnTimeLeft:= 0; |
|
548 | 114 |
if AliveCount = 0 then |
1011 | 115 |
begin // draw |
116 |
AddCaption(trmsg[sidDraw], $FFFFFF, capgrpGameState); |
|
117 |
SendStat(siGameResult, trmsg[sidDraw]); |
|
118 |
AddGear(0, 0, gtATFinishGame, 0, _0, _0, 3000) |
|
119 |
end else // win |
|
120 |
with AliveClan^ do |
|
121 |
begin |
|
122 |
if TeamsNumber = 1 then |
|
123 |
s:= Format(trmsg[sidWinner], Teams[0]^.TeamName) // team wins |
|
124 |
else |
|
125 |
s:= Format(trmsg[sidWinner], Teams[0]^.TeamName); // clan wins |
|
549 | 126 |
|
1011 | 127 |
for j:= 0 to Pred(TeamsNumber) do |
128 |
with Teams[j]^ do |
|
129 |
for i:= 0 to cMaxHHIndex do |
|
130 |
with Hedgehogs[i] do |
|
131 |
if (Gear <> nil) then |
|
132 |
Gear^.State:= gstWinner; |
|
133 |
||
134 |
AddCaption(s, $FFFFFF, capgrpGameState); |
|
135 |
SendStat(siGameResult, s); |
|
136 |
AddGear(0, 0, gtATFinishGame, 0, _0, _0, 3000) |
|
137 |
end; |
|
307 | 138 |
SendStats |
83 | 139 |
end; |
140 |
||
4 | 141 |
procedure SwitchHedgehog; |
551 | 142 |
var c: LongWord; |
351 | 143 |
g: PGear; |
552 | 144 |
PrevHH, PrevTeam: LongWord; |
4 | 145 |
begin |
146 |
FreeActionsList; |
|
147 |
TargetPoint.X:= NoPointX; |
|
89 | 148 |
TryDo(CurrentTeam <> nil, 'nil Team', true); |
547 | 149 |
|
944 | 150 |
with CurrentHedgehog^ do |
294 | 151 |
if Gear <> nil then |
152 |
begin |
|
540 | 153 |
AttacksNum:= 0; |
351 | 154 |
Gear^.Message:= 0; |
534 | 155 |
Gear^.Z:= cHHZ; |
156 |
RemoveGearFromList(Gear); |
|
157 |
InsertGearToList(Gear) |
|
294 | 158 |
end; |
4 | 159 |
|
550 | 160 |
c:= CurrentTeam^.Clan^.ClanIndex; |
4 | 161 |
repeat |
550 | 162 |
c:= Succ(c) mod ClansCount; |
163 |
with ClansArray[c]^ do |
|
164 |
repeat |
|
552 | 165 |
PrevTeam:= CurrTeam; |
550 | 166 |
CurrTeam:= Succ(CurrTeam) mod TeamsNumber; |
167 |
CurrentTeam:= Teams[CurrTeam]; |
|
168 |
with CurrentTeam^ do |
|
552 | 169 |
begin |
170 |
PrevHH:= CurrHedgehog; |
|
550 | 171 |
repeat |
552 | 172 |
CurrHedgehog:= Succ(CurrHedgehog) mod HedgehogsNumber; |
173 |
until (Hedgehogs[CurrHedgehog].Gear <> nil) or (CurrHedgehog = PrevHH) |
|
174 |
end |
|
175 |
until (CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear <> nil) or (PrevTeam = CurrTeam); |
|
550 | 176 |
until CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear <> nil; |
83 | 177 |
|
602 | 178 |
CurrentHedgehog:= @(CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog]); |
944 | 179 |
SwitchNotHoldedAmmo(CurrentHedgehog^); |
602 | 180 |
with CurrentHedgehog^ do |
4 | 181 |
begin |
182 |
with Gear^ do |
|
183 |
begin |
|
294 | 184 |
Z:= cCurrHHZ; |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
17
diff
changeset
|
185 |
State:= gstHHDriven; |
4 | 186 |
Active:= true |
187 |
end; |
|
294 | 188 |
RemoveGearFromList(Gear); |
189 |
InsertGearToList(Gear); |
|
4 | 190 |
FollowGear:= Gear |
191 |
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
|
192 |
|
b5222ddafe1f
- Fix bug with picking up ammos from cases, when total ammo count may become more than AMMO_INFINITE
unc0rr
parents:
927
diff
changeset
|
193 |
inc(CurrentTeam^.Clan^.TurnNumber); |
b5222ddafe1f
- Fix bug with picking up ammos from cases, when total ammo count may become more than AMMO_INFINITE
unc0rr
parents:
927
diff
changeset
|
194 |
|
4 | 195 |
ResetKbd; |
351 | 196 |
|
197 |
cWindSpeed:= rndSign(GetRandom * cMaxWindSpeed); |
|
498 | 198 |
g:= AddGear(0, 0, gtATSmoothWindCh, 0, _0, _0, 1); |
351 | 199 |
g^.Tag:= hwRound(cWindSpeed * 72 / cMaxWindSpeed); |
4 | 200 |
{$IFDEF DEBUGFILE}AddFileLog('Wind = '+FloatToStr(cWindSpeed));{$ENDIF} |
602 | 201 |
ApplyAmmoChanges(CurrentHedgehog^); |
800 | 202 |
|
351 | 203 |
if CurrentTeam^.ExtDriven then SetDefaultBinds |
204 |
else SetBinds(CurrentTeam^.Binds); |
|
176 | 205 |
bShowFinger:= true; |
800 | 206 |
|
801 | 207 |
if (CurrentTeam^.ExtDriven or (CurrentHedgehog^.BotLevel > 0)) then |
208 |
PlaySound(sndIllGetYou, false) |
|
209 |
else |
|
210 |
PlaySound(sndYesSir, false); |
|
800 | 211 |
|
4 | 212 |
TurnTimeLeft:= cHedgehogTurnTime |
213 |
end; |
|
214 |
||
549 | 215 |
function AddTeam(TeamColor: Longword): PTeam; |
351 | 216 |
var Result: PTeam; |
549 | 217 |
c: LongInt; |
4 | 218 |
begin |
547 | 219 |
TryDo(TeamsCount <= cMaxTeams, 'Too many teams', true); |
17 | 220 |
New(Result); |
80 | 221 |
TryDo(Result <> nil, 'AddTeam: Result = nil', true); |
4 | 222 |
FillChar(Result^, sizeof(TTeam), 0); |
351 | 223 |
Result^.AttackBar:= 2; |
224 |
Result^.CurrHedgehog:= cMaxHHIndex; |
|
547 | 225 |
|
226 |
TeamsArray[TeamsCount]:= Result; |
|
227 |
inc(TeamsCount); |
|
228 |
||
549 | 229 |
c:= Pred(ClansCount); |
230 |
while (c >= 0) and (ClansArray[c]^.Color <> TeamColor) do dec(c); |
|
231 |
if c < 0 then |
|
232 |
begin |
|
233 |
new(Result^.Clan); |
|
234 |
FillChar(Result^.Clan^, sizeof(TClan), 0); |
|
235 |
ClansArray[ClansCount]:= Result^.Clan; |
|
236 |
inc(ClansCount); |
|
237 |
with Result^.Clan^ do |
|
238 |
begin |
|
550 | 239 |
ClanIndex:= Pred(ClansCount); |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
240 |
Color:= TeamColor |
549 | 241 |
end |
242 |
end else |
|
243 |
begin |
|
244 |
Result^.Clan:= ClansArray[c]; |
|
245 |
end; |
|
246 |
||
247 |
with Result^.Clan^ do |
|
248 |
begin |
|
249 |
Teams[TeamsNumber]:= Result; |
|
250 |
inc(TeamsNumber) |
|
251 |
end; |
|
252 |
||
351 | 253 |
CurrentTeam:= Result; |
254 |
AddTeam:= Result |
|
4 | 255 |
end; |
256 |
||
257 |
procedure FreeTeamsList; |
|
547 | 258 |
var t: LongInt; |
4 | 259 |
begin |
547 | 260 |
for t:= 0 to Pred(TeamsCount) do Dispose(TeamsArray[t]); |
261 |
TeamsCount:= 0 |
|
4 | 262 |
end; |
263 |
||
47 | 264 |
procedure RecountAllTeamsHealth; |
547 | 265 |
var t: LongInt; |
266 |
begin |
|
267 |
for t:= 0 to Pred(TeamsCount) do |
|
268 |
RecountTeamHealth(TeamsArray[t]) |
|
47 | 269 |
end; |
270 |
||
271 |
procedure InitTeams; |
|
547 | 272 |
var i, t: LongInt; |
371 | 273 |
th: LongInt; |
47 | 274 |
begin |
547 | 275 |
for t:= 0 to Pred(TeamsCount) do |
276 |
with TeamsArray[t]^ do |
|
47 | 277 |
begin |
278 |
th:= 0; |
|
4 | 279 |
for i:= 0 to cMaxHHIndex do |
547 | 280 |
if Hedgehogs[i].Gear <> nil then |
281 |
inc(th, Hedgehogs[i].Gear^.Health); |
|
47 | 282 |
if th > MaxTeamHealth then MaxTeamHealth:= th; |
4 | 283 |
end; |
47 | 284 |
RecountAllTeamsHealth |
4 | 285 |
end; |
286 |
||
287 |
function TeamSize(p: PTeam): Longword; |
|
351 | 288 |
var i, Result: Longword; |
4 | 289 |
begin |
290 |
Result:= 0; |
|
291 |
for i:= 0 to cMaxHHIndex do |
|
351 | 292 |
if p^.Hedgehogs[i].Gear <> nil then inc(Result); |
293 |
TeamSize:= Result |
|
4 | 294 |
end; |
295 |
||
549 | 296 |
procedure RecountClanHealth(clan: PClan); |
297 |
var i: LongInt; |
|
298 |
begin |
|
299 |
with clan^ do |
|
300 |
begin |
|
301 |
ClanHealth:= 0; |
|
302 |
for i:= 0 to Pred(TeamsNumber) do |
|
303 |
inc(ClanHealth, Teams[i]^.TeamHealth) |
|
304 |
end |
|
305 |
end; |
|
306 |
||
47 | 307 |
procedure RecountTeamHealth(team: PTeam); |
371 | 308 |
var i: LongInt; |
47 | 309 |
begin |
310 |
with team^ do |
|
311 |
begin |
|
557 | 312 |
NewTeamHealthBarWidth:= 0; |
47 | 313 |
for i:= 0 to cMaxHHIndex do |
314 |
if Hedgehogs[i].Gear <> nil then |
|
557 | 315 |
inc(NewTeamHealthBarWidth, Hedgehogs[i].Gear^.Health); |
316 |
TeamHealth:= NewTeamHealthBarWidth; |
|
317 |
if NewTeamHealthBarWidth > MaxTeamHealth then |
|
47 | 318 |
begin |
557 | 319 |
MaxTeamHealth:= NewTeamHealthBarWidth; |
47 | 320 |
RecountAllTeamsHealth; |
557 | 321 |
end else NewTeamHealthBarWidth:= (NewTeamHealthBarWidth * cTeamHealthWidth) div MaxTeamHealth |
49 | 322 |
end; |
549 | 323 |
|
324 |
RecountClanHealth(team^.Clan); |
|
325 |
||
498 | 326 |
AddGear(0, 0, gtTeamHealthSorter, 0, _0, _0, 0) |
47 | 327 |
end; |
328 |
||
72 | 329 |
procedure RestoreTeamsFromSave; |
547 | 330 |
var t: LongInt; |
72 | 331 |
begin |
547 | 332 |
for t:= 0 to Pred(TeamsCount) do |
333 |
TeamsArray[t]^.ExtDriven:= false |
|
72 | 334 |
end; |
335 |
||
4 | 336 |
initialization |
337 |
||
338 |
finalization |
|
339 |
||
340 |
FreeTeamsList |
|
341 |
||
342 |
end. |