author | unc0rr |
Thu, 08 May 2008 21:27:59 +0000 | |
changeset 919 | fadfefc2ae40 |
parent 883 | 07a568ba44e0 |
child 927 | 2c1675344a6f |
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 |
AltSlot, AltAmmo: LongWord; |
|
39 |
Team: PTeam; |
|
40 |
AttacksNum: Longword; |
|
41 |
visStepPos: LongWord; |
|
5 | 42 |
BotLevel : LongWord; // 0 - Human player |
814
7fb4417b7bc1
Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
801
diff
changeset
|
43 |
stats: TStatistics; |
4 | 44 |
end; |
45 |
TTeam = record |
|
549 | 46 |
Clan: PClan; |
74 | 47 |
TeamName: string[MAXNAMELEN]; |
4 | 48 |
ExtDriven: boolean; |
167 | 49 |
Binds: TBinds; |
4 | 50 |
Hedgehogs: array[0..cMaxHHIndex] of THedgehog; |
551 | 51 |
CurrHedgehog: LongWord; |
762 | 52 |
NameTagTex: PTexture; |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
53 |
CrosshairTex, |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
54 |
GraveTex, |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
55 |
HealthTex: PTexture; |
4 | 56 |
GraveName: string; |
57 |
FortName: string; |
|
371 | 58 |
TeamHealth: LongInt; |
557 | 59 |
TeamHealthBarWidth, |
60 |
NewTeamHealthBarWidth: LongInt; |
|
371 | 61 |
DrawHealthY: LongInt; |
4 | 62 |
AttackBar: LongWord; |
550 | 63 |
HedgehogsNumber: Longword; |
4 | 64 |
end; |
549 | 65 |
TClan = record |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
66 |
Color: Longword; |
549 | 67 |
Teams: array[0..Pred(cMaxTeams)] of PTeam; |
68 |
TeamsNumber: Longword; |
|
551 | 69 |
CurrTeam: LongWord; |
549 | 70 |
ClanHealth: LongInt; |
550 | 71 |
ClanIndex: LongInt; |
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; |
548 | 99 |
t, AliveCount: 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 |
83 | 115 |
begin // draw |
116 |
AddCaption(trmsg[sidDraw], $FFFFFF, capgrpGameState); |
|
306 | 117 |
SendStat(siGameResult, trmsg[sidDraw]); |
498 | 118 |
AddGear(0, 0, gtATFinishGame, 0, _0, _0, 2000) |
83 | 119 |
end else // win |
549 | 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 |
|
126 |
||
127 |
AddCaption(s, $FFFFFF, capgrpGameState); |
|
128 |
SendStat(siGameResult, s); |
|
129 |
AddGear(0, 0, gtATFinishGame, 0, _0, _0, 2000) |
|
130 |
end; |
|
307 | 131 |
SendStats |
83 | 132 |
end; |
133 |
||
4 | 134 |
procedure SwitchHedgehog; |
551 | 135 |
var c: LongWord; |
351 | 136 |
g: PGear; |
552 | 137 |
PrevHH, PrevTeam: LongWord; |
4 | 138 |
begin |
139 |
FreeActionsList; |
|
140 |
TargetPoint.X:= NoPointX; |
|
89 | 141 |
TryDo(CurrentTeam <> nil, 'nil Team', true); |
547 | 142 |
|
351 | 143 |
with CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog] do |
294 | 144 |
if Gear <> nil then |
145 |
begin |
|
540 | 146 |
AttacksNum:= 0; |
351 | 147 |
Gear^.Message:= 0; |
534 | 148 |
Gear^.Z:= cHHZ; |
553
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
552
diff
changeset
|
149 |
SwitchNotHoldedAmmo(CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog]); |
534 | 150 |
RemoveGearFromList(Gear); |
151 |
InsertGearToList(Gear) |
|
294 | 152 |
end; |
4 | 153 |
|
550 | 154 |
c:= CurrentTeam^.Clan^.ClanIndex; |
4 | 155 |
repeat |
550 | 156 |
c:= Succ(c) mod ClansCount; |
157 |
with ClansArray[c]^ do |
|
158 |
repeat |
|
552 | 159 |
PrevTeam:= CurrTeam; |
550 | 160 |
CurrTeam:= Succ(CurrTeam) mod TeamsNumber; |
161 |
CurrentTeam:= Teams[CurrTeam]; |
|
162 |
with CurrentTeam^ do |
|
552 | 163 |
begin |
164 |
PrevHH:= CurrHedgehog; |
|
550 | 165 |
repeat |
552 | 166 |
CurrHedgehog:= Succ(CurrHedgehog) mod HedgehogsNumber; |
167 |
until (Hedgehogs[CurrHedgehog].Gear <> nil) or (CurrHedgehog = PrevHH) |
|
168 |
end |
|
169 |
until (CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear <> nil) or (PrevTeam = CurrTeam); |
|
550 | 170 |
until CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear <> nil; |
83 | 171 |
|
602 | 172 |
CurrentHedgehog:= @(CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog]); |
173 |
with CurrentHedgehog^ do |
|
4 | 174 |
begin |
175 |
with Gear^ do |
|
176 |
begin |
|
294 | 177 |
Z:= cCurrHHZ; |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
17
diff
changeset
|
178 |
State:= gstHHDriven; |
4 | 179 |
Active:= true |
180 |
end; |
|
294 | 181 |
RemoveGearFromList(Gear); |
182 |
InsertGearToList(Gear); |
|
4 | 183 |
FollowGear:= Gear |
184 |
end; |
|
185 |
ResetKbd; |
|
351 | 186 |
|
187 |
cWindSpeed:= rndSign(GetRandom * cMaxWindSpeed); |
|
498 | 188 |
g:= AddGear(0, 0, gtATSmoothWindCh, 0, _0, _0, 1); |
351 | 189 |
g^.Tag:= hwRound(cWindSpeed * 72 / cMaxWindSpeed); |
4 | 190 |
{$IFDEF DEBUGFILE}AddFileLog('Wind = '+FloatToStr(cWindSpeed));{$ENDIF} |
602 | 191 |
ApplyAmmoChanges(CurrentHedgehog^); |
800 | 192 |
|
351 | 193 |
if CurrentTeam^.ExtDriven then SetDefaultBinds |
194 |
else SetBinds(CurrentTeam^.Binds); |
|
176 | 195 |
bShowFinger:= true; |
800 | 196 |
|
801 | 197 |
if (CurrentTeam^.ExtDriven or (CurrentHedgehog^.BotLevel > 0)) then |
198 |
PlaySound(sndIllGetYou, false) |
|
199 |
else |
|
200 |
PlaySound(sndYesSir, false); |
|
800 | 201 |
|
4 | 202 |
TurnTimeLeft:= cHedgehogTurnTime |
203 |
end; |
|
204 |
||
549 | 205 |
function AddTeam(TeamColor: Longword): PTeam; |
351 | 206 |
var Result: PTeam; |
549 | 207 |
c: LongInt; |
4 | 208 |
begin |
547 | 209 |
TryDo(TeamsCount <= cMaxTeams, 'Too many teams', true); |
17 | 210 |
New(Result); |
80 | 211 |
TryDo(Result <> nil, 'AddTeam: Result = nil', true); |
4 | 212 |
FillChar(Result^, sizeof(TTeam), 0); |
351 | 213 |
Result^.AttackBar:= 2; |
214 |
Result^.CurrHedgehog:= cMaxHHIndex; |
|
547 | 215 |
|
216 |
TeamsArray[TeamsCount]:= Result; |
|
217 |
inc(TeamsCount); |
|
218 |
||
549 | 219 |
c:= Pred(ClansCount); |
220 |
while (c >= 0) and (ClansArray[c]^.Color <> TeamColor) do dec(c); |
|
221 |
if c < 0 then |
|
222 |
begin |
|
223 |
new(Result^.Clan); |
|
224 |
FillChar(Result^.Clan^, sizeof(TClan), 0); |
|
225 |
ClansArray[ClansCount]:= Result^.Clan; |
|
226 |
inc(ClansCount); |
|
227 |
with Result^.Clan^ do |
|
228 |
begin |
|
550 | 229 |
ClanIndex:= Pred(ClansCount); |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
230 |
Color:= TeamColor |
549 | 231 |
end |
232 |
end else |
|
233 |
begin |
|
234 |
Result^.Clan:= ClansArray[c]; |
|
235 |
end; |
|
236 |
||
237 |
with Result^.Clan^ do |
|
238 |
begin |
|
239 |
Teams[TeamsNumber]:= Result; |
|
240 |
inc(TeamsNumber) |
|
241 |
end; |
|
242 |
||
351 | 243 |
CurrentTeam:= Result; |
244 |
AddTeam:= Result |
|
4 | 245 |
end; |
246 |
||
247 |
procedure FreeTeamsList; |
|
547 | 248 |
var t: LongInt; |
4 | 249 |
begin |
547 | 250 |
for t:= 0 to Pred(TeamsCount) do Dispose(TeamsArray[t]); |
251 |
TeamsCount:= 0 |
|
4 | 252 |
end; |
253 |
||
47 | 254 |
procedure RecountAllTeamsHealth; |
547 | 255 |
var t: LongInt; |
256 |
begin |
|
257 |
for t:= 0 to Pred(TeamsCount) do |
|
258 |
RecountTeamHealth(TeamsArray[t]) |
|
47 | 259 |
end; |
260 |
||
261 |
procedure InitTeams; |
|
547 | 262 |
var i, t: LongInt; |
371 | 263 |
th: LongInt; |
47 | 264 |
begin |
547 | 265 |
for t:= 0 to Pred(TeamsCount) do |
266 |
with TeamsArray[t]^ do |
|
47 | 267 |
begin |
268 |
th:= 0; |
|
4 | 269 |
for i:= 0 to cMaxHHIndex do |
547 | 270 |
if Hedgehogs[i].Gear <> nil then |
271 |
inc(th, Hedgehogs[i].Gear^.Health); |
|
47 | 272 |
if th > MaxTeamHealth then MaxTeamHealth:= th; |
4 | 273 |
end; |
47 | 274 |
RecountAllTeamsHealth |
4 | 275 |
end; |
276 |
||
277 |
function TeamSize(p: PTeam): Longword; |
|
351 | 278 |
var i, Result: Longword; |
4 | 279 |
begin |
280 |
Result:= 0; |
|
281 |
for i:= 0 to cMaxHHIndex do |
|
351 | 282 |
if p^.Hedgehogs[i].Gear <> nil then inc(Result); |
283 |
TeamSize:= Result |
|
4 | 284 |
end; |
285 |
||
549 | 286 |
procedure RecountClanHealth(clan: PClan); |
287 |
var i: LongInt; |
|
288 |
begin |
|
289 |
with clan^ do |
|
290 |
begin |
|
291 |
ClanHealth:= 0; |
|
292 |
for i:= 0 to Pred(TeamsNumber) do |
|
293 |
inc(ClanHealth, Teams[i]^.TeamHealth) |
|
294 |
end |
|
295 |
end; |
|
296 |
||
47 | 297 |
procedure RecountTeamHealth(team: PTeam); |
371 | 298 |
var i: LongInt; |
47 | 299 |
begin |
300 |
with team^ do |
|
301 |
begin |
|
557 | 302 |
NewTeamHealthBarWidth:= 0; |
47 | 303 |
for i:= 0 to cMaxHHIndex do |
304 |
if Hedgehogs[i].Gear <> nil then |
|
557 | 305 |
inc(NewTeamHealthBarWidth, Hedgehogs[i].Gear^.Health); |
306 |
TeamHealth:= NewTeamHealthBarWidth; |
|
307 |
if NewTeamHealthBarWidth > MaxTeamHealth then |
|
47 | 308 |
begin |
557 | 309 |
MaxTeamHealth:= NewTeamHealthBarWidth; |
47 | 310 |
RecountAllTeamsHealth; |
557 | 311 |
end else NewTeamHealthBarWidth:= (NewTeamHealthBarWidth * cTeamHealthWidth) div MaxTeamHealth |
49 | 312 |
end; |
549 | 313 |
|
314 |
RecountClanHealth(team^.Clan); |
|
315 |
||
498 | 316 |
AddGear(0, 0, gtTeamHealthSorter, 0, _0, _0, 0) |
47 | 317 |
end; |
318 |
||
72 | 319 |
procedure RestoreTeamsFromSave; |
547 | 320 |
var t: LongInt; |
72 | 321 |
begin |
547 | 322 |
for t:= 0 to Pred(TeamsCount) do |
323 |
TeamsArray[t]^.ExtDriven:= false |
|
72 | 324 |
end; |
325 |
||
4 | 326 |
initialization |
327 |
||
328 |
finalization |
|
329 |
||
330 |
FreeTeamsList |
|
331 |
||
332 |
end. |